javascript - Vue.js 中的替代绑定(bind)语法

标签 javascript php angularjs vue.js

问题

我想知道在 Vue.js 中是否有替代语法来输出数据,而不是花括号 like the ng-bind Angular directive .

阅读文档,似乎 Vue.js accepts only tag properties使用 v-bind 指令,但我希望它也能与内部 html 一起工作。

上下文

我想使用 PHP 输出数据,并在页面加载后使用 Vue 管理它。想象下一种情况:

我们想要这样的输出:

 <div>Hello</div> 

首先我们用php输出数据

 <div><?php echo $hello_string ?></div> 

在那之后,我们希望能够用 Vue 改变内容。当前的语法是;

 <div>{{ hello_string }}</div> 

我们不能混合这两种语法,所以我需要这样的东西:

<!--Ideal syntax for mixing vue and php-->
<div v-bind:innerhtml="hello_string"><?php echo $hello_string ?></div> 

感谢您的帮助。

最佳答案

您可以使用 v-text指令:

<div v-text="hello_string"></div>
<!-- same as -->
<div>{{ hello_string }}</div>

v-html :

<div v-html="html"></div>
<!-- same as -->
<div>{{{ html }}}</div>

关于javascript - Vue.js 中的替代绑定(bind)语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34404843/

相关文章:

javascript - 在 Ember 中如何使用 View 更改 css 属性然后查看它?

php - 在 Silex 中将用户添加到防火墙的用户列表

php - stdClass 类的对象无法转换为字符串 - laravel

javascript - NG-STYLE 在 angularjs 中不起作用

Javascript 不重新加载父级

javascript - Angular 从子组件更新 UI 将值反射(reflect)到父组件

javascript - 最后以特殊字符排序

php - 从表 jQuery 获取 anchor 标记类/id

angularjs - 为什么在 Angular 中使用 ng-src 时必须使用表达式?

javascript - 处理非英文实体名称