javascript - 在 Vue.js 中将属性作为组件参数传递

标签 javascript html binding vue.js

我正在 Vue.js 中创建一个测试组件。我想传递一个参数以在我的模板中使用,如下所示:

Vue.component('test', {
   props: ['href'],
   template: '<li><a href="{{href}}"><slot></slot></a></li>'
});

在我的 html 文件中:

<test href="/">Tvest</test>

但是属性 href 未绑定(bind)到属性。

<li><a href="{{href}}">Tvest</a></li>

如何在 Vue.js 中正确执行此操作?

最佳答案

您需要get rid of the brackets围绕 href 并指定您要使用 v-bind directive 绑定(bind)数据属性:

<li><a v-bind:href="href"><slot></slot></a></li>

关于javascript - 在 Vue.js 中将属性作为组件参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45312755/

相关文章:

javascript - 如何在预定义的 html 表中显示来自 javascript 数组的图像

html - iOS7:在固定覆盖层中滚动会导致主体滚动

html - YouTube 电影无法加载

wpf - 在上下文菜单命令参数 mvvm 中获取行

javascript - 为类似数据结构的区 block 链对象数组排序

javascript - innerHTML 基础,在循环中添加数字

javascript - 将类添加到 html 根目录

c++ - OpenGL 在已经绑定(bind)时绑定(bind)

c# - 为什么我的绑定(bind)只能以一种方式工作?

javascript - 如何将数据从appdelegate传递到jquerymobile中的index.html