gpt4 book ai didi

templates - Vue.js 本地模板变量

转载 作者:行者123 更新时间:2023-12-01 12:09:07 24 4
gpt4 key购买 nike

我需要在我的 Vue 模板中创建一个局部变量来缩短对其他长对象的引用 $v.form.text ,如下例所示:

<input 
:class="{ error: !$v.form.text.required }"
v-model.trim="$v.form.text.$model"
/>

我希望能够访问 $v.form.text我模板中的嵌套对象很简单 text .
<input 
:class="{ error: !text.required }"
v-model.trim="text.$model"
/>

通常有比上面的例子更多的代码,证明创建一个临时变量是正确的,但问题与所示相同。

Note: I have already solved this, please see answer below, and simply want to document the solution for others who might be searching for the same.

最佳答案

我刚刚遇到了同样的问题,并想到了另一个黑客/解决方法......注意我还没有尝试过,但应该可以工作。

只需将 v-for 与包含长表达式的单个内联数组一起使用,即

<span v-for="item in [my.big.long.expression.item]">{{item.foo}} {{item.bar}}</span>

:)

关于templates - Vue.js 本地模板变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53732201/

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