【问题标题】:How to pass a string with double quoutes as property in VueJS?如何在 Vue JS 中将带双引号的字符串作为属性传递?
【发布时间】:2018-02-20 23:39:51
【问题描述】:

我只是尝试使用如下代码:

<editor init-text="String "Test""></editor>

但是由于给定字符串中的 qoutes,DOM 会中断。

如何避免这个问题?

【问题讨论】:

标签: vue.js


【解决方案1】:

\转义引号

<editor init-text="String \"Test\""></editor>

或者混合单引号'和双引号"

<editor init-text='String "Test"'></editor>

【讨论】:

  • 单引号可以提供帮助,直到我也遇到字符串中的单引号。那对我不起作用。只有“实体有效。
  • 或者您可以在data() 中声明一个带有刻度引号的字符串并使用:init-text。 IE。在模板中:&lt;editor :init-text="str"&gt;&lt;/editor&gt;。在&lt;script&gt;data() { return { str: `String "Test" String 'Test'` }; }
猜你喜欢
  • 2017-08-21
  • 2019-08-20
  • 1970-01-01
  • 2019-11-20
  • 2014-06-11
  • 2016-07-22
  • 2011-02-13
  • 2011-11-28
  • 1970-01-01
相关资源
最近更新 更多