gpt4 book ai didi

javascript - 正在为未受影响的其他组件触发 Vue 指令

转载 作者:行者123 更新时间:2023-12-03 02:36:45 25 4
gpt4 key购买 nike

我有一个指令:

Vue.directive('autosave', {
componentUpdated(el) {
console.log(el);
},
})

我有 2 个元素(vuetify):

this is a wrapper around input
<v-text-field label="Field 1" v-model="model1" v-autosave></v-text-field>
<v-text-field label="Field 2" v-model="model2" v-autosave></v-text-field>

如果我对第一个输入进行更改,则两个输入的指令都会被调用。为什么是这样?如何才能只调用受影响的元素?

Vue版本:2.5.3
Vuetify 版本:1.0.0-beta.4

最佳答案

根据the docs :

componentUpdated: called after the containing component’s VNode andthe VNodes of its children have updated.

它被调用是因为包含组件的 VNode 已更新。您似乎期望它像 inputchange 事件一样工作。你为什么不使用 v-on

你可能应该做的是输入 watch关于你的变量。

关于javascript - 正在为未受影响的其他组件触发 Vue 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48512024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com