Vue.js change {{ }} tags

2019-01-23 10:46发布

I want to change the {{ something }} by <% something %> in Vue.js, how could I achieve that, is it even possible?

An equivalent for what I look for in AngularJS:

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

Thanks a lot for your help!

标签: vue.js
3条回答
手持菜刀,她持情操
2楼-- · 2019-01-23 11:33

You should modify the delimiters property of configuration object.

Vue.config.delimiters = ['<%', '%>']

Edit: This solution works for Vue 1.x and lower. See @Skip and @jaynabonne responses for Vue 2.x solution

查看更多
孤傲高冷的网名
3楼-- · 2019-01-23 11:40

With the latest version (2.0.5), the above doesn't work. Rather than assigning to the global config, you pass the delimiters as an option to the Vue instance:

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

At least, that's what I had to do to make it work.

查看更多
贪生不怕死
4楼-- · 2019-01-23 11:41

I am running Vue 2.1.0 standalone and this is what I had to use

Vue.options.delimiters = ['{[{', '}]}'];
查看更多
登录 后发表回答