简体   繁体   English

是否可以使用 Vue 在 HTML 属性中包含双花括号?

[英]Is it possible to include double curly braces inside an HTML attribute using Vue?

Let's say I want to have <input value='{{default}}'></input> in regular HTML.假设我想在常规 HTML 中使用<input value='{{default}}'></input> The textbox with {{default}} as a default input will be displayed.将显示以{{default}}作为默认输入的文本框。

However I'm trying to do such thing with Vue but, won't work as expected但是我正在尝试用 Vue 做这样的事情,但是不会按预期工作

<md-input value='{{document_url}}'></md-input>

The error I'm getting is我得到的错误是

in ./node_modules/vue-loader/lib/template-compiler?{"id":"data-v-c9c99006","hasScoped":false,"preserveWhitespace":false,"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0&bustCache!./components/template-heuristic-cases.vue
(Emitted value instead of an instance of Error)

Use the v-bind instead of just using html value property:使用v-bind而不是仅使用 html value属性:

<input :value="'{{default}}'">

This will output:这将输出:

{{default}} in the browser. {{default}}在浏览器中。


For further case, if you want to bind the data option in the value then just concatenate them:对于进一步的情况,如果您想在value绑定数据选项,则只需将它们连接起来:

<input :value="'{{'+mydata+'}}'">

// ... inside data option:
mydata: 'my default'

Had similar situation and simply accomplished with:有类似的情况,只需完成:

<input :value="document_url">

if outside of HTML element, use version with double curly braces:如果在 HTML 元素之外,请使用带双花括号的版本:

<span>{{document_url}}</span>

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

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