我是按vue官网上的教程写的,一共两个文件:
main.js
import Vue from 'vue';
import App from './app.vue';
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
new Vue({
el:'#app',
// render:function(creater){
// return creater(App);
// }
})
index.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>kkk</title>
</head>
<body>
<div id='app'>
<button-counter></button-counter>
</div>
</body>
</html>
查看webpack渲染后的html源代码是这样的:
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>kkk</title>
</head>
<body>
<div id='app'>
<button-counter></button-counter>
</div>
<script type="text/javascript" src="./build.js"></script></body>
</html>
但是页面上没有任何东西,f12检查元素也看不到这个自定义的组件,只在body标签内
<!--function(t,n,r,o){return cn(e,t,n,r,o,!0)}-->
有一行这个,
这是什么问题?请高手指教
我运行了一下你的代码,(去除了import App from './app.vue';这句,因为我本地没有app.vue文件
一切正常,跟官网表现一致