我安装了 vue-cli (webpack-simple)
src/main.js:
import Vue from 'vue'
import App from './App.vue'
new Vue({
delimiters: ['?{', '}'], // here , delimiters set " ?{ } "
el: '#app',
render: h => h(App)
})
以上代码不起作用 (?{}
),{}
继续工作
/src/App.vue代码更改
<template>
<div id="app">
?{ msg }
</div>
</template>
<script>
export default {
name: "app",
delimiters: ["?{", "}"], // here , delimiters set " ?{ } "
data() {
return {
msg: "Welcome to Your Vue.js App"
};
}
};
</script>
index.html(不起作用):
<div> ?{ msg } </div>
我想打印“欢迎使用您的 Vue.js 应用程序”
帮帮我
谢谢!!
最佳答案
查看作者的回复:
Delimiters can only be changed when using runtime compilation with the full build (vue.js). It does not work in *.vue files (to keep all *.vue files syntax consistent)
Vue 2.5.1 Component custom delimiter not working #5697
[2020/07/03]
如何配置使用运行时编译器来使用自定义分隔符
创建
vue.config.js
文件位于项目根目录(您存储的位置package.json
)添加内容如下:
// vue.config.js
module.exports = {
runtimeCompiler: true
}
- 删除
<template />
在app.vue
- 修改
<script />
在app.vue
如下:
// app.vue
<script>
export default {
delimiters: ['{', '}'],
name: 'App',
template: '<div id="app">{ title }</div>',
data () {
return {
title: 'This is a Title'
};
}
};
</script>
关于javascript - 如何更改 vue-cli 的分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57407615/