Javascript vue代码可以';t向我的参数发送值。什么';怎么了?
作为我的代码,参数Javascript vue代码可以';t向我的参数发送值。什么';怎么了?,javascript,vue.js,Javascript,Vue.js,作为我的代码,参数dbtask总是null 从中,我们可以得到如下数据: [{"idknowledgedescription": null, "idexercise": null, "answerpath": "浙江数学文testpdf.pdf", "value": null, "iddailytask": 1, "briefanswer": "A", "time": null, "idstudents": 1, "exercisepath": "浙江数学文testpdf.pdf", "time
dbtask
总是null
从中,我们可以得到如下数据:
[{"idknowledgedescription": null, "idexercise": null, "answerpath": "浙江数学文testpdf.pdf", "value": null, "iddailytask": 1, "briefanswer": "A", "time": null, "idstudents": 1, "exercisepath": "浙江数学文testpdf.pdf", "timeofplan": "2018-03-15", "timeoflearn": "2018-03-15T00:00:00", "anserofstudent": null, "tipspath": "浙江数学文testpdf.pdf"}]
{%load static%}
{%verbatim%}
{{t.exercisepath}
{%endverbatim%}
var app6=新的Vue({
el:“#app-6”,
数据:{
dbtask:null,
},
创建(){
设置超时(()=>{
这个.bbb()
}, 1000);
},
方法:{
bbb:函数(){
var self=这个;
$.getJSON('http://127.0.0.1:8000/tasks/,职能(任务){
self.dbtask=任务;
警报(self.dbtask[0].exercisepath);
});
}.绑定(此)
}
})
`
在方法声明中,删除.bind(this)
。它将方法函数绑定到窗口
对象,而不是Vue实例
换句话说,当您使用方法时:{myMethod:function(){console.log(this);}.bind(this)}
,在myMethod
内部,this
将是窗口,而不是Vue实例
下面是这方面的快速演示:
newvue({
el:“#应用程序”,
数据:{
消息:“您好,Vue.js!”
},
方法:{
regularMethod:function(){console.log('regular method',this.message);},
bindThisMethod:function(){console.log('methodwith.bind(this)',this.message);}.bind(this)
},
创建(){
这个.regularMethod();
this.bindThisMethod();
}
})
{{message}}
在方法声明中,删除.bind(this)
。它将方法函数绑定到窗口
对象,而不是Vue实例
换句话说,当您使用方法时:{myMethod:function(){console.log(this);}.bind(this)}
,在myMethod
内部,this
将是窗口,而不是Vue实例
下面是这方面的快速演示:
newvue({
el:“#应用程序”,
数据:{
消息:“您好,Vue.js!”
},
方法:{
regularMethod:function(){console.log('regular method',this.message);},
bindThisMethod:function(){console.log('methodwith.bind(this)',this.message);}.bind(this)
},
创建(){
这个.regularMethod();
this.bindThisMethod();
}
})
{{message}}
是。它起作用了。谢谢你第二次帮助我!当然,总是乐于助人!:)对它起作用了。谢谢你第二次帮助我!当然,总是乐于助人!:)