问题是我无法通过属性将动态Pug变量通过属性传递给Vue组件,如果它们是“ String”类型的话。 Vue将我要传递的字符串视为Vue属性的名称。
问题
template.pug
- var pugVariable = 'John';
my-component(v-bind:name= pugVariable)
* MyComponent.Vue *
export default {
name: 'MyComponent',
props: {
name: {
type: String
}
}
}
我得到一个错误:“属性或方法“ John”未在实例上定义,但在渲染过程中被引用。”,据我所知,这意味着Vue将pugVariable
中的字符串视为Vue属性的名称。
问题
所以,问题是:现在说服Vue将此变量视为字符串?
我已经尝试过的方法:
我尝试传递对象文字而不是字符串,如下所示:
my-component(v-bind:name= {value: pugVariable})
它可以工作,但是我们无法检查传递的值的类型,因此我不喜欢这种解决方案。
答案 0 :(得分:0)
无论谁,我都早早得到了答案:)
如此处https://stackoverflow.com/a/45175556/7473709所述,如果我们只想传递静态字符串,就必须简单地删除v-bind:
前缀,因此如下所示:
my-component(name= {value: pugVariable})