我正在使用Vue2,并将我的项目重构为使用Vue3。
做了该做的一切,但不能与data() {..}交互
下面是data设置:
data() {
return {
rules: {
first: 1,
second: 2,
third: 3,
},
// ... and more variables & objects
}
},我正在设置变量&
data中的对象,有些是常量,另一些是方法中的更改。
并使用data
template:
<input type="file"
@change="changeEvent"
:multiple="this.rules.first > 1"
/>methods:
changeEvent() {
if(this.rules.first == 1) { //.. do something }
}与Options API与Vue2的工作相同。
但是在升级到Vue3之后,在console中得到了这个error:
Uncaught (in promise) TypeError: Cannot read property 'rules' of undefined此外:
[Vue warn]: Unhandled error during execution of setup function
[Vue warn]: Unhandled error during execution of scheduler flush.也适用于在variables中定义的所有objects和data()
我在Vue3中读到了有关Vue3的信息,也许我可以使用它,但现在我正试图挽救这个项目的生命。
我还读到,我仍然可以使用Options API和Vue3。
那么,为什么相同的Options API代码不能工作呢?
发布于 2021-07-11 12:26:00
您不应该在模板中使用this:
<input type="file"
@change="changeEvent"
:multiple="rules.first > 1"
/>https://stackoverflow.com/questions/68336039
复制相似问题