admin管理员组

文章数量:1287569

In Vue.js 1.0, I can set global delimiters by the following codes

Vue.config.delimiters = ['${', '}'];

But It was removed from Vue.js 2.0. Must I use the following codes to set delimiters every time?

new Vue({
  delimiters: ['${', '}']
})

In Vue.js 1.0, I can set global delimiters by the following codes

Vue.config.delimiters = ['${', '}'];

But It was removed from Vue.js 2.0. Must I use the following codes to set delimiters every time?

new Vue({
  delimiters: ['${', '}']
})
Share Improve this question edited Dec 23, 2017 at 6:43 Vishal 1,2721 gold badge12 silver badges19 bronze badges asked Dec 10, 2016 at 12:20 caimaoycaimaoy 1,2281 gold badge12 silver badges27 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

For Vue2, try it like this:

Vue.options.delimiters = ['${', '}'];

As far as I'm aware there is no way to set the delimiters globally, here's the explanation why:

...in 2.0 delimiters will bee a ponent-level option, which means you only need to set it for the root instance that relies on in-DOM templates. Any ponents processed by vueify or vue-loader can just keep using default delimiters.

The change is intended to make it easier to use 3rd party ponents, since changing the delimiters globally means you will not be able to pile them correctly.

Source: https://github./vuejs/vue-cli/issues/100

But what about simple workaround. You can prepare class, const or any kind of config like:

VueConfig.js

export const VueConfig = { delimiters: ['${', '}'] };

and then on your App.js you simply do

```

import {VueConfig} from './VueConfig';

new Vue(
    Object.assign(VueConfig, {
        el: '#app',
        data: {
            msg: 'Oh my app',
        }
    })
);

```

Effect is like here: http://take.ms/wiPGR

本文标签: javascriptHow to set global delimiters in Vuejs 20Stack Overflow