本文介绍了vuejs 2 nextTick() 返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 vuejs 2 中使用 nextTick() 返回一些数据,如下所示
I'm trying to return some data using nextTick() in vuejs 2 as following
getProperty() {
this.$nextTick(function() {
return 'hello';
});
}
它不起作用.有什么线索吗?
It doesn't work. Any clue?
推荐答案
this.$nextTick
这个函数不返回任何东西;它只是在刷新所有新数据后执行您的回调.
this.$nextTick
this function does not return anything; it just executes your callback after refreshing all new data.
所以如果你想设置一些标志或数据,你可以使用模态/变量.
so if you want to set some flag or data you can use modal/variable for that.
new Vue({
data: {
msg: 'hello'
},
methods: {
someTask: function () {
this.msg = 'hello next tick';
this.$nextTick(function() {
this.printVar();
});
},
printVar: function() {
// here this variable will be changed to latest value
// or call another function where this value is used
// this.anotherFunction();
console.log(this.msg);
}
},
ready: function () {
this.someTask();
}
});
或者只是告诉我们您想用它做什么,以便我们为您提供更好的答案.
or just let us know what you want to do with that so we can provide you better answer.
这篇关于vuejs 2 nextTick() 返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!