【问题标题】:invalid expression: Invalid or unexpected token in Vue.js for-loop无效表达式:Vue.js for 循环中的无效或意外标记
【发布时间】:2018-06-22 12:26:11
【问题描述】:

我有一个像下面这样的 v-for div:

<div
              v-for="(item_disk, index_disk) in $store.state.buy_physicalserver_disk_list"
            >

            <Button

              :type="get_choose_disk_type(item_disk)"
              :key="index_disk"
              @click="select_disk(item_disk)"
            
    >
              {{ item_disk.content }}  // if I comment this line it will works fine.
            
    </Button>
          </div>

在这种情况下我会出错。

invalid expression: Invalid or unexpected token in "\n     "+_s(item_disk.content)+"\n        " Raw expression: {{ item_disk.content }}

看我的代码,如果我评论{{ item_disk.content }},就不会有这个问题了。

【问题讨论】:

  • this.$store.state.buy_physicalserver_disk_list 来自哪里?那是组件数据吗?
  • 你的模板中有这个吗?你不要在模板中用 $this 调用数据,只是变量名。
  • 看起来很清楚;它不喜欢item_disk.content 中的某些内容。它的价值是什么?
  • item_disk.content 只是一个字符串。

标签: vue.js


【解决方案1】:

我知道这个问题,使用

<Button>{{item.content}}</Button>

得到错误,但如果我使用

<Button v-text="item.content"></Button>

不会有这个问题。

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    相关资源
    最近更新 更多