Laravel 如何在方法中获得对已装载vue.js的响应?
我对使用Laravel学习Vue.js非常陌生 我试图在我的方法中得到响应,我只是不知道怎么做 我不确定我是否做对了 目前发生的情况是,我无法访问挂载中的Laravel 如何在方法中获得对已装载vue.js的响应?,laravel,vue.js,Laravel,Vue.js,我对使用Laravel学习Vue.js非常陌生 我试图在我的方法中得到响应,我只是不知道怎么做 我不确定我是否做对了 目前发生的情况是,我无法访问挂载中的response\u data的值,当我试图对其进行控制台操作时,它总是返回null export default { data() { return { response_data: "", } }, methods: { get
response\u data
的值,当我试图对其进行控制台操作时,它总是返回null
export default {
data() {
return {
response_data: "",
}
},
methods: {
getData() {
axios.get('api/random').then((res) => {
return this.response_data = res.data;
}).catch((error) => {
console.log(error);
})
},
saveData() {
axios.post('api/random').then((res) => {
this.getData();
})
}
},
mounted() {
this.getData();
console.log(this.getData())
document.addEventListener('DOMContentLoaded', function(event) {
window.onload = function() {
// array with text to type
var dataText = [
"Hello, here is some text typing along a spiral path. Hello, here is some text typing along a spiral path. Hello, here is some text typing along a spiral path. Hello, here is some text typing along a spiral path."
];
//text input caret
var caret = "\u258B";
// type a text
// keep calling itself until the text is finished
function type(text, i, fnCallback) {
// chekc if text isn't finished yet
if (i < (text.length)) {
// add next character to text + caret
document.querySelector("#text").textContent = text.substring(0, i + 1) + caret;
// delay and call this function again for next character
setTimeout(function() {
type(text, i + 1, fnCallback)
}, 70);
}
// text finished, call callback if there is a callback function
else if (typeof fnCallback == 'function') {
// call callback after timeout
setTimeout(fnCallback, 1500);
}
}
// start animation for a text in the dataText array
function StartAnimation(i) {
if (typeof dataText[i] == 'undefined') {
setTimeout(function() {
StartAnimation(0);
}, 1000);
}
// check if dataText[i] exists
if (i < dataText[i].length) {
// text exists! start typewriter animation
type(dataText[i], 0, function() {
// after callback (and whole text has been animated), start next text
StartAnimation(i + 1);
});
}
}
// start the text animation
StartAnimation(0);
}
});
}
}
导出默认值{
数据(){
返回{
响应_数据:“”,
}
},
方法:{
getData(){
获取('api/random')。然后((res)=>{
返回this.response_data=res.data;
}).catch((错误)=>{
console.log(错误);
})
},
saveData(){
axios.post('api/random')。然后((res)=>{
这是getData();
})
}
},
安装的(){
这是getData();
console.log(this.getData())
document.addEventListener('DOMContentLoaded',函数(事件){
window.onload=函数(){
//包含要键入的文本的数组
var dataText=[
“您好,这是一些沿螺旋路径键入的文本。您好,这是一些沿螺旋路径键入的文本。您好,这是一些沿螺旋路径键入的文本。您好,这是一些沿螺旋路径键入的文本。”
];
//文本输入插入符号
var插入符号=“\u258B”;
//键入文本
//一直调用自己,直到文本完成
函数类型(文本、i、fnCallback){
//如果文本尚未完成,请检查
如果(i<(文本长度)){
//将下一个字符添加到文本+插入符号
document.querySelector(“#text”).textContent=text.substring(0,i+1)+插入符号;
//延迟并为下一个字符再次调用此函数
setTimeout(函数(){
类型(文本,i+1,fnCallback)
}, 70);
}
//文本完成后,如果有回调函数,则调用callback
else if(typeof fnCallback=='function'){
//超时后调用回调
setTimeout(fnCallback,1500);
}
}
//为dataText数组中的文本启动动画
功能启动(一){
如果(数据文本[i]的类型=='undefined'){
setTimeout(函数(){
StartAnimation(0);
}, 1000);
}
//检查dataText[i]是否存在
if(i
我的目标是操作我在
getData
函数中要装载的响应数组,这样我就可以将它存储在变量dataText
中。有人能帮我找到正确的方法吗。你能在:1中提供更多信息吗。目前正在发生什么?2.预期的行为是什么?您的代码不会尝试在任何地方读取response\u数据
(它只设置它)。