[英]Bind dynamically value to component's props
我用道具定义了自定义组件。 当我使用此组件时,我需要将值动态绑定到这些道具的一个上
在自定义组件的模板中,我定义了如下元素:
<template>
...
<div class="input-group-addon" v-show="currency">{{ currency }}</div>
...
</template>
及其道具:
export default {
...
props: {
currency: {
type: String
}
}
...
}
组件在另一个组件中的用法:
组件的模板
<custom-component currency="calculateCurrency" ></custom-component>
组件的代码
export default {
components: {custom-component},
data: () => ({
myProject: null // this is used as v-model in combo box
}),
computed: {
calculateCurrency: function() {
return myProject.currency; // currency is getter in object myProject
}
}
}
我也尝试使用
suffix=calculateCurrency
没有引号,但没有帮助。 你能帮我解决吗? 谢谢
我相信您在绑定属性上缺少冒号:
<custom-component :currency="calculateCurrency" ></custom-component>
在“ currency”之前添加它可以进行数据绑定
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.