【发布时间】:2019-11-22 12:55:32
【问题描述】:
我试图了解为什么我在 Vue 项目的屏幕上看不到任何内容。我查看了一个 Vue CLI 生成的项目,在main.js 中看到了这段代码:
new Vue({
render: h => h(App),
}).$mount('#appmodified')
但我使用以下代码,基于sample TODO sandbox:
new Vue({
el: '#appmodified',
template: '<App/>',
components: { App }
})
当我运行npm run build时,这种实例化Vue的方式不会返回任何警告或错误:
> @ build C:\wamp64\www\vuewtest
> vue-cli-service build
\ Building for production...
DONE Compiled successfully in 1858ms 13:14:40
File Size Gzipped
dist\js\chunk-vendors.6018a262.js 65.29 KiB 23.49 KiB
dist\js\index.377fe308.js 1.96 KiB 1.01 KiB
Images and other types of assets omitted.
DONE Build complete. The dist directory is ready to be deployed.
INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
尽管构建完成且没有错误,为什么我的代码在浏览器中没有显示任何内容?
main.js:
import Vue from 'vue'
import App from './App'
Vue.config.productionTip = false
/* eslint-disable no-new */
//************ this works ************
new Vue({
render: h => h(App),
}).$mount('#appmodified')
//************ this does not work *************
new Vue({
el: '#appmodified',
template: '<App/>',
components: { App }
})
vue.config.js:
module.exports = {
"publicPath": "",
pages: {
index:{
entry: "main.js",
template: "index.html"
}
}
}
package.json:
{
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"@vue/cli-service": "^3.9.2",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10"
}
}
【问题讨论】: