繁体   English   中英

将 html 元素字符串传递给 vue 自定义指令,eslint 问题

[英]Pass html element string to vue custom directive, issue with eslint

我创建了两个自定义 vue 指令来在另一个元素之后或之前插入一个 html 元素,我将一个 html 元素字符串传递给应用该指令的元素,但 VS Code 给了我以下错误:

Parsing error: unexpected-character-in-attribute-name.eslint-plugin-vue

这就是我的做法:

<rad-stack title="Precio final" v-insert-before="'<div class="RADcard3_texts_info_divider"></div>'">{{ item.finalPrice }} €</rad-stack>

我的指令如下所示:

Vue.directive('insert-before', {
    isLiteral: true,
    inserted: (el, binding, vnode) => {
        el.parentNode.insertBefore(binding.value, el);
    }
});

问题在于双引号"" 由于 html 属性值用双引号括起来,我们不能在字符串中使用它们。

您可以将值分配给实例变量并在模板中引用它,如下所示,

Vue 模板

<rad-stack title="Precio final" v-insert-before="prefixMsg">{{ item.finalPrice }} €</rad-stack>

Vue 脚本

data() {
 return {
   prefixMsg: '<div class="RADcard3_texts_info_divider"></div>'
 }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM