我真的很难应对以下情况:

一些索引页:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8"/>
  </head>
  <body>
    <div id="app">

      <ul>
        <li>some existing option</li>
        <example-component :foo="foo" :bar="bar"/>
      </ul>

      <a @click.prevent="showDetail(1, 'abc')" href="#" >Click ME!</a>

    </div>


    <script src="app.js"></script>


  </body>
</html>

一些单文件组件:

<template>
    <li><a v-show="checkBool" data-toggle="tab" class="some-class" href="#container-div" data-tab-url="{{ this.foo }}">{{ this.bar }}</a></li>
</template>



<script>
export default {

  props: ['foo', 'bar'],


  computed: {
    checkBool: function() {
      return (this.foo != undefined && this.bar != undefined )
    }

  }

}
</script>

app.js号看起来像这样:

import Vue from 'vue'

Vue.component('example-component', require('ExampleComponent.vue'));

const app = new Vue({
    el: '#app',

    props: [
      'foo',
      'bar'
    ],

    data: {
      foo: '',
      bar: ''
    },

     methods: {
      showDetail: function (foo, bar) {
        this.foo = foo,
        this.bar = bar
      }
  }
});

我使用的是laravel安装下带有网页包的babel.

情况是这样的:

  • 当我点击Click ME!链接时,foobar被更新并传递给组件(这部分正在工作)
  • 本例中名为checkBool的computed属性变为true,因此我将看到新的列表项(这部分正在工作)
  • 新列表项,有一个链接,文本正确设置为bar(这部分也在工作)

在这一点上,我知道组件和父组件之间的值设置和通信工作正常,但是data-tab-url="{{ this.foo }}"部分让我抓狂.

我没有像预期的那样解析mustache 语法并返回data-tab-url="1",而是得到引号之间所有内容的解析/转义值.

大约data-tab-url="%7B%7B+this.foo+%7D%7D".

现在,我如何防止编码发生?

推荐答案

像这样绑定属性:data-tab-url="foo".

这将为受影响的元素提供一个data-tab-url属性,其值等于组件的foo属性.

Vue.js相关问答推荐

try 在类星应用程序中使用Vue插件(Vue 3 Mq)-如何配置?

Vue路由路径匹配行为

为什么元素会从Vue 3中的TransitionGroup左上角出现?

如何只提取一次用于无线电组过滤的数据,而不是针对数据库中的每个条目提取数据?

Vue.js 3 运行时挂载组件实例

Nuxt 和 Vite 有什么区别?

无法在 Vuex 中的其他操作中反跳操作

在下拉菜单上使用箭头键滚动

在textbox文本框 VueJS 2 中键入时搜索列表

vuejs中watch方法和计算方法有什么区别

Vue-Router 抽象父路由

vuejs挂载生命周期未触发

触发子函数

Select 下拉列表中的复选框后如何清除 v-autocomplete(多个)搜索输入?

简单的点击功能不触发

使计算的 Vue 属性依赖于当前时间?

偶数行格式化

带有 Firebase 云消息传递的 Vue pwa 无法正常工作

在 Vuex 模块中进行继承的方法

vuejs 中缺少 webpack 配置