Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 如何在Vue中将v-for值绑定到HTML属性_Vue.js_Vuejs2_Vue Component - Fatal编程技术网

Vue.js 如何在Vue中将v-for值绑定到HTML属性

Vue.js 如何在Vue中将v-for值绑定到HTML属性,vue.js,vuejs2,vue-component,Vue.js,Vuejs2,Vue Component,我正在尝试将从v-for中获得的值附加到同一标记中的属性,但运气不好。这是我的密码: <label v-for="hashtag in hashtags" v-bind:title=`You can filter with {hashtag}` v-bind:data-value="hashtag" ></label> 基本上,该值会转到标题和数据值您的标题绑定应该在表达式之前和之后有双引号,而且您似乎希望在标题中插入字符

我正在尝试将从v-for中获得的值附加到同一标记中的属性,但运气不好。这是我的密码:

 <label 
      v-for="hashtag in hashtags" 
      v-bind:title=`You can filter with {hashtag}`
      v-bind:data-value="hashtag"
 ></label>


基本上,该值会转到
标题
数据值

您的标题绑定应该在表达式之前和之后有双引号,而且您似乎希望在标题中插入字符串,但我认为这不起作用

试试这个(你可以使用ommitv-bindcus
这是它的缩写)


{{hashtag}}

这里需要注意的一件重要事情是,如果使用v-bing/
,则
=
的右侧必须是javascript有效表达式,因为它将由vue计算<代码>:sum=“5+5”将计算为数字10
sum=“5+5”
将计算为字符串
5+5
。使用string
:title=“'a'+'string'”
您需要在双引号内加一个引号才能使其正常工作。
<label v-for="hashtag in hashtags"  :title="'You can filter with ' + hashtag" :data-value="hashtag">
   {{ hashtag }}
</label>