vue.js - 将带有祖父母中定义的道具的数据传递给孙子
问题描述
父类:
<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}}
有没有办法将表达式传递给道具?
解决方案
您应该使用v-bind:name="icon"
绑定将属性与属性绑定:
<BaseIcon v-bind:name="icon" />
或简写:
<BaseIcon :name="icon" />
推荐阅读
- css - 如何使用 Angular Material 为任何组件添加背景?
- javascript - 如何创建通用分页功能?
- git - 在 Windows 7 中通过 atom 在 git bash 中打开文件
- c# - 如何直接从流中读取二进制数组?
- c# - 使用 microsoft/azure 的 Asp.net WebAPP 登录在 chrome 中不起作用
- memory - 该硬件如何通过通信总线将 32 位值的寄存器地址仅增加一个?
- automation - 我正面临 CircularTimer 如何使用 appium 移动应用程序处理它的问题
- mysql - where子句MYSQL中的参数中的JSON文本
- java - Eclipse IDE 中的 JAX-RS PathSegment @PathParam 错误
- android - 图像未在 android api 19 及更低版本中加载毕加索