Javascript VueJS 2中的watchEffect等效于什么
在VueJS 2组件中,我在加载组件时填充一个props变量Javascript VueJS 2中的watchEffect等效于什么,javascript,vue.js,Javascript,Vue.js,在VueJS 2组件中,我在加载组件时填充一个props变量 created() { this.events = null Service.getEvents() .then(response => { this.events = response.data }) .catch(error => { console.log(error.response) }) } } 我需要在单
created() {
this.events = null
Service.getEvents()
.then(response => {
this.events = response.data
})
.catch(error => {
console.log(error.response)
})
}
}
我需要在单击下一页时用“事件”道具重新加载组件。我看到了VueJS3教程,其中使用watchEffect方法()重新加载props变量
VueJS 2中此功能的等效功能是什么
我尝试对这个变量使用watch()方法,但这会导致无限递归,因为“events”对象在该方法中发生了更改
//Error - recusrsion
watch: {
events() {
this.events = null
Service.getEvents()
.then(response => {
console.log(response.data)
this.events = response.data
})
.catch(error => {
console.log(error.response)
})
}
},
当用户单击按钮/链接时,我们如何在同一页面中重新加载事件?关于代码
这一点。事件
表示监视的变量
所以它会导致递归
如果要在上添加事件,请单击下一页
然后添加
@点击=
事件道具到下一页的组件上,道具在你的代码上。事件
表示观察的变量
所以它会导致递归
如果要在上添加事件,请单击下一页
然后添加
@单击=
下一页道具组件上的事件道具在选项中观察api接收旧值和新值:
watch: {
event: function (oldEventData, newEventData) {
console.log(newEventData) // do something with new event data
}
},
在选项api中观察接收旧值和新值:
watch: {
event: function (oldEventData, newEventData) {
console.log(newEventData) // do something with new event data
}
},
@jinseok oh我应该怎么做才能在同一页/组件中重新加载事件数据?你能描述更多细节吗?创建重新加载事件并将函数附加到@click=@jinseok oh我应该怎么做才能在同一页/组件中重新加载事件数据?你能描述更多细节吗?创建重新加载事件并将函数附加到的方法吗@点击=