【发布时间】:2022-01-12 18:35:45
【问题描述】:
这段代码来自VueMastery课程,一定是过时的:
export default {
setup(props, {emit}){
let email = props.email;
let toggleRead = () => {
email.read = !email.read
axios.put(`http://localhost:3000/emails/${email.id}`, email)
}
...
它给出了这个错误:
71:9 error Getting a value from the `props` in root scope of `setup()` will cause the value to lose reactivity vue/no-setup-props-destructure
请注意,我在这里不是在处理 const 。在 Vue 3 中使 prop 值反应的正确方法是什么?
【问题讨论】:
-
使用toRefs
-
或者根据props创建一个计算值