vue.js - 我该如何解决 "Interpolation inside attributes has been removed. Use v-bind or the colon shorthand"? Vue.js 2

标签 vue.js vuejs2 vue-component

我的 Vue.js 组件是这样的:

    <template>
        <div>
            <div class="panel-group" v-for="item in list">
                ...
                <div class="panel-body">
                    <a role="button" data-toggle="collapse" href="#purchase-{{ item.id }}" class="pull-right" aria-expanded="false" aria-controls="collapseOne">
                        Show
                    </a>
                </div>
                <div id="purchase-{{ item.id }}" class="table-responsive panel-collapse collapse" role="tabpanel">
                ...
                </div>
            </div>
        </div>
    </template>

    <script>
        export default {
            ...
            computed: {
                list: function() {
                    return this.$store.state.transaction.list
                },
                ...
            }
        }
    </script>

执行时出现如下错误:

Vue template syntax error:

id="purchase-{{ item.id }}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead.

我该如何解决?

最佳答案

v-bind(或快捷方式“:”)中使用 JavaScript 代码:

:href="'#purchase-' + item.id"

:id="'purchase-' + item.id"

或者如果使用 ES6或以后:

:id="`purchase-${item.id}`"

关于vue.js - 我该如何解决 "Interpolation inside attributes has been removed. Use v-bind or the colon shorthand"? Vue.js 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43211760/

相关文章:

javascript - 如何正确删除 vue-select 多选项

javascript - View | vue-moment.js 的问题

javascript - 向 Vue 实例的 destroy 钩子(Hook)添加回调

javascript - 在 nuxt.js 上为 vuetify app v2.0 添加暗模式切换

javascript - 从 Vue.js 2 中的方法内推送到数组

javascript - 类导入到Vue组件中

javascript - 如何通过 props 传递导入的组件?

webpack - 在 vue cli 3 生成的项目中启动开发服务器

javascript - Vue Scoped Slots 组件和插槽之间的双向数据绑定(bind)

javascript - 从父组件向 VeeValidate 错误包添加错误并从子组件监听