【问题标题】:Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead [duplicate]属性内的插值已被删除。改用 v-bind 或冒号简写[重复]
【发布时间】:2018-04-22 06:55:14
【问题描述】:

我很难理解如何通过 html 将值传递给 vue,它总是给我这个错误:属性内的插值已被删除。改用 v-bind 或冒号简写

编辑:我想将值“country”传递给 vue 实例,这不起作用,有人可以给我一个关于 HTML 和 vue 方面的例子吗?

这是我的代码:

HTML

<div id="image-slider" :country="@{{country}}">
<template id="slider-template">
<p>
<a class="featured-providers-arrow-left" @click="prevRow"><img src="{{route('cacheImage', ['newDesign', 'arrow.png']) }}"/></a>
</p>
<a class="featured-providers-arrow-right" @click="nextRow"><img src="{{route('cacheImage', ['newDesign', 'arrow.png']) }}"/></a>
</template>
</div>

VUE

new Vue({
el: '#image-slider',
  data: {
    providers: []
  },
  mounted(){
    this.country = this.$el.attributes.country.value;
    this.$http.get('/provider-' + this.country).then(response => response.data = this.providers);/*this.providers = response.data);*/
  },
  currentNumber: 0,
  timer:null
}

【问题讨论】:

  • 图片中src属性前加冒号即可。

标签: html vue.js


【解决方案1】:

Vuejs 不再支持文本插值。 As explained here

删除属性内的插值

属性内的插值不再有效。

例如:

<button class="btn btn-{{ size }}"></button> 

应该更新 使用内联表达式:

<button v-bind:class="'btn btn-' + > size"></button>

所以,这基本上意味着与 Vuejs 1.x 中的语法不同:

<img src="{{someValue}}">

在 2.x 中不再支持它。所以你必须把它改成:

<img :src="someValue">

【讨论】:

  • 不完全是,我现在在这里有这个值: :country="{{ $country }}" 在我的代码中 $country 是 country => 'string' 样式的对象想要将此对象传递给 vue,但是,例如,如果字符串是“瑞典”,它会给我以下错误消息:“[Vue 警告]:属性或方法“瑞典”未在实例上定义,但在渲染期间被引用。确保通过初始化属性,该属性是反应性的,无论是在数据选项中,还是对于基于类的组件。但是我要传递的属性是对象而不是值“瑞典”我需要在这里做什么?跨度>
  • 你不能做:country冒号必须附加到已知的html属性,如valuesrcclassdisabled等...如果你想使用/pass data called country 你必须像这样传递它:data-country='country'
  • 我尝试使用 :data-country='country' 但我收到了同样的错误,使用刀片将简单的对象值传递给 vue 似乎相当复杂..... :(( (
  • 你可以给我一把小提琴吗? :))
  • 你想得到国家?
猜你喜欢
  • 2017-07-22
  • 2018-05-19
  • 2019-01-30
  • 2020-06-18
  • 1970-01-01
  • 2017-04-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多