vue学习笔记三
才发现写了两篇一直是webpack的东西。今天用点vue的组件:
根目录下新建一个template文件夹, 顾名思义,是用来放vue组件的
在template新建一个hello.vue
hello.vue里面写点东西,顺便加点样式
<template lang="html">
<div id="hello">
{{message}},{{name}}
</div>
</template>
<script>
export default {
name:"hello",
data(){
return {
message:"hello",
name:"world"
}
}
}
</script>
<style lang="css">
#hello{
font-size:14px;
color:#ff0202
}
</style>
修改src/js/index.js文件
引入我们刚刚写的.vue模板
import
helloVue
from
'./../../template/hello.vue'
;
之前的data数据我们现在可以不要了, 删掉后注册引入的组件
new Vue({
el:
"#app"
,
components: {
"helloVue"
:
helloVue
}
})
修改根目录的index.html文件;
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"ie=edge"
>
<
title
>vue_study</
title
>
</
head
>
<
body
>
<
div
id
=
"app"
>
<
hello-vue
></
hello-vue
>
</
div
>
</
body
>
</
html
>
只留刚刚的注册的那个组件
安装 vue-loader 模块;
然后我们需要修改webpack.config.js;
添加vue的解析:
{
test:
/
\.
vue
$
/
,
use: [
'vue-loader'
]
},
到这里基本上已经完成了。
执行打包:
webpack
如果没有意外的话,刷新页面应该是这样的
到这里一个基本的.vue打包已经完成了。
下次我们写个dotolist
我也是一个vue新人,有什么不对的地方欢迎大家指正交流