Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

vue的属性插值表达式的问题

我用Element的菜单组件,定义json

menus = [
 {
  name:'首页',
  icon:'`location`'
 }
]

页面中

<el-submenu v-for="(item,index) in menus">
    <template slot="title">
          <i class="el-icon-{{item.icon}}"></i>
          <span>{{item.name}}</span>
    </template>
</el-submenu>

报错说class必须用:class,然后改成

<i :class="el-icon-{{item.icon}}">

报错说必须给:class赋值

像这种需求,要怎么搞?需要在属性中用插值表达式。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<i :class="`el-icon-${item.icon}`"></i>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...