使用ajax更新数据时,vuejs不会第二次呈现数据
我正在使用vue js更新我页面上的一些内容,这是一个真正简单的用例使用ajax更新数据时,vuejs不会第二次呈现数据,ajax,vue.js,vue-component,Ajax,Vue.js,Vue Component,我正在使用vue js更新我页面上的一些内容,这是一个真正简单的用例 Vue.component('my-component', { template: '.....<a v-on:click="myfunction">data</a>{{stuff}}' data: { stuff: 0 } mounted(){ let __this = this; axios.....then(func
Vue.component('my-component', {
template: '.....<a v-on:click="myfunction">data</a>{{stuff}}'
data: {
stuff: 0
}
mounted(){
let __this = this;
axios.....then(function (data){ __this.stuff = 1l }); // works
}
methods: {
myfunction: function(){
this.stuff = 2; /// dosnt work. template not rendered
}
}
});
Vue.component('my-component'){
模板:“……数据{{stuff}}”
数据:{
资料:0
}
安装的(){
让这个=这个;
axios…..然后(函数(数据){uuuu this.stuff=1l});//工作
}
方法:{
myfunction:function(){
this.stuff=2;///dosnt-work.template未呈现
}
}
});
设置变量以检测更改或任何指针的任何特定方法?谢谢。对于可重用组件,您的
数据
字段实际上应该是一个返回数据对象的函数:
Vue.component('my-component', {
template: '.....<a v-on:click="myfunction">data</a>{{stuff}}',
data() {
return {
stuff: 0
};
},
mounted(){
let __this = this;
axios.....then(function (data){ __this.stuff = 1l }); // works
},
methods: {
myfunction: function(){
this.stuff = 2; // should work now
}
}
});
Vue.component('my-component'){
模板:“……有关此问题的详细信息。请确保您已在mounted()
之外定义了方法
?格式错误抱歉,现在已解决此问题。