父类:
<template>
<BaseButton icon="activity">Slotted Text</BaseButton>
</template>
子类:BaseButton
<template>
<div>
{{ icon }} // returns the expected result; prop is coming in.
<slot>Default Text</slot>
<BaseIcon :name="{{icon}}" /> <-- error is here, see below.
</div>
</template>
<script>
export default {
props: {
icon: {
type: String,
required: true,
},
},
}
孙子:
<template>
<div class="icon-wrapper" v-html="svg"></div>
</template>
<script>
export default {
props: {
name: String
}
// code that uses the name prop
}
</script>
错误是:
Unexpected token '{' in
{{icon}}
有没有办法将表达式传递到 prop 中?
答案 0 :(得分:1)
您应该使用绑定 v-bind:name="icon"
将属性与属性绑定:
<BaseIcon v-bind:name="icon" />
或简写:
<BaseIcon :name="icon" />