uni-app属性值的动态绑定

1.问题

使用传统的方法给标签的属性动态绑定数据报错。

2.错误重现

2.1 错误代码

2.2 错误信息

Module Error (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):
10:01:33.690 (Emitted value instead of an instance of Error) 
10:01:33.703   Errors compiling template:
10:01:33.704   src="{{imgeSrc}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of 
, use
.

2.3 错误原因

      因为vue 2.x不支持对属性使用插值{{}}的方式赋值,所以要使用v-bind指令(或简写“:”)来指定属性。

3.解决方案(以image标签讲解)

  • v-bind指令

  v-bind:src="imgeSrc"

  • v-bind简写指令:
  :src="imgeSrc"

 

你可能感兴趣的:(前端,vue,vue.js,uniapp,属性动态绑定,vue标签)