vue里面使用转义字符

1,806 阅读1分钟

第一种方式就是直接使用

  
                <div>
                    &#xe788;
                </div>

后来因为需要写菜单图标

1634529180(1).png

这是一个二级菜单,下面还有一级,图标是需要根据数据发生变化的 于是我定义数据,并作判断


 if (this.clickIndex == "0") {
                this.icon[0] = "&#xe788;";
                this.icon[1] = "&#xe604;";
                this.icon[2] = "&#xe62a;";
                this.icon[3] = "&#xe790;";
                this.icon[4] = "&#xe649;";
                this.icon[5] = "&#xe53d;";
            } else if (this.clickIndex == "1") {
                this.icon[0] = "&#xe6c0;";
                this.icon[1] = "&#xec23;";
                this.icon[2] = "&#xe656;";
                this.icon[3] = "&#xe790;";
                this.icon[4] = "&#xe64a;";
                this.icon[5] = "&#xe636;";
                this.icon[6] = " &#xe63a;";
            } else {
            }

然后再使用{{ }}引用

最后是显示字符串 并没有转义

于是我仔细查询各种资料,终于研究出方法

使用v-html

<span class="iconfont" v-html="icon[index]"> </span>


这样图标就能实现出来了