【发布时间】:2022-01-01 12:23:46
【问题描述】:
如何使用 Pug 在 Vue 模板中正确添加动态属性名称?我正在使用以下模板:
<template lang="pug">
button(id=`button__${buttontype}`)
slot(name="text")
</template>
<script>
export default {
name: "Button",
data() {
return {
buttontype: "primary"
},
},
mounted() {
console.log(this.test); // This shows the value as 'primary'
},
};
</script>
正在生成的 HTML 元素是<button id="button__undefined"></button>
出于某种原因,buttontype 的值在 id 属性中以undefined 的形式出现。
【问题讨论】:
-
是的,有效!谢谢!