Vue.js更改{{}}标记

Ham*_*bot 39 vue.js

我想改{{ something }}<% something %>在Vue.js,我怎么能做到这一点,是它甚至可能吗?

我在AngularJS中寻找的等价物:

var app = angular.module('app', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('<%');
    $interpolateProvider.endSymbol('%>');
});
Run Code Online (Sandbox Code Playgroud)

非常感谢你的帮助!

小智 83

使用最新版本(2.0.5),上述功能无效.您可以将分隔符作为选项传递给Vue实例,而不是分配给全局配置:

new Vue({
    el: '#app',
    data: data,
    delimiters: ["<%","%>"]
});
Run Code Online (Sandbox Code Playgroud)

至少,这就是我必须做的才能让它发挥作用.


小智 28

我独立运行Vue 2.1.0,这是我必须使用的

Vue.options.delimiters = ['{[{', '}]}'];
Run Code Online (Sandbox Code Playgroud)


Pan*_*lis 27

您应该修改delimiters配置对象的属性.

Vue.config.delimiters = ['<%', '%>']
Run Code Online (Sandbox Code Playgroud)

编辑:此解决方案适用于Vue 1.x及更低版本.请参阅Vue 2.x解决方案的@Skip和@jaynabonne响应

  • 显然这在Vue 2.4.2中对我不起作用 (2认同)

Nic*_*ivi 5

如果您使用的是 Vue 3.x,文档会告诉您这样做:

Vue.createApp({
  // Delimiters changed to ES6 template string style
  delimiters: ['${', '}']
})
Run Code Online (Sandbox Code Playgroud)