vue.js - 通过vue-cli建立 vue2.1.10项目,报cannot read property 'text'

查看:146
本文介绍了vue.js - 通过vue-cli建立 vue2.1.10项目,报cannot read property 'text'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

通过vue-cli建立 vue2.1.10项目,报cannot read property 'text' of undefined

App.vue代码为

<template>
<section>
  <div class="highlight" slot="highlight">
    <pre>
        <div class="hljs language-html"> <span class="hljs-tag">&lt;</span>
           
      </div>
  </pre>
</div>
</section></template>
<script>
  
  export default {
    data() {
      return {
        value1: true,
       
      }
    }
  };
</script>

但App.vue内容为

<template>
<section>
  <div class="highlight" slot="highlight">
    <pre>
        <div class="hljs language-html"> 
           
      </div>
  </pre>
</div>
</section></template>
<script>
  
  export default {
    data() {
      return {
        value1: true,
       
      }
    }
  };
</script>

就不会报错,下面只比上面少了<span class="hljs-tag">&lt;</span>,真是太奇怪了。

解决方案

因为<pre></pre>标签里面的特殊符号&lt;会被转成符号实体< 所以你实际这里的代码是这样的

<span class="hljs-tag"><</span>

自然就无法识别了

这篇关于vue.js - 通过vue-cli建立 vue2.1.10项目,报cannot read property &#039;text&#039;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆