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
3 Answers
Reset to default 8For 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
版权声明:本文标题:javascript - How to set global delimiters in Vue.js 2.0? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741313056a2371759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论