创建一个空文件夹,打开命令行安装
npm init -y // 格式化
cnpm i vue-cli -g // 全局安装
vue -V // 查看版本
vue init webpack // 选择 Y n n n
cnpm i // 安装
npm run dev // 启动服务器
vue-cli 布局
下载完之后找到文件夹src
App.vue
<template>
<div>
<my-header></my-header>
<my-content></my-content>
<my-footer></my-footer>
</div>
</template>
<script type="text/javascript">
import MyHeader from "./components/myheader" // 路径 导入
import MyContent from "./components/mycontent"
import MyFooter from "./components/myfooter"
export default { // 导出
components:{
// MyHeader:MyHeader,
// MyContent:MyContent,
// MyFooter:MyFooter //原来写法
MyHeader,MyContent,MyFooter //缩写
}
}
</script>
在src里的components文件夹里创建 myheader.vue / mycontent.vue / myfooter.vue / mynav.vue
myheader.vue
<template>
<p>头部</p>
</template>
<script>
</script>
<style>
</style>
mycontent.vue
<template>
<div>
<p>内容</p>
<ul>
<li v-for="x in list1">{{x}}</li>
</ul>
<div>
<tab titles="11,22,33" contents="aa,bb,cc"></tab>
<tab titles="aa,bb,cc,dd" contents="11,22,33,44"></tab>
<tab titles="Aa,Bb,Cc" contents="1-1,2-1,3-1"></tab>
</div>
</div>
</template>
<script>
import tab from "./mynav"
export default{
data(){
return{
list:["电脑","电视机","手机","洗衣机","电影票","衣服"],
keys:"",
list1:[]
}
},
components:{
tab
},
methods:{
find(){
if(this.keys=="") return [];
var temp=[];
this.list.forEach(function(item){
if(item.includes(this.keys)){
temp.push(item);
}
}.bind(this))
this.list1=temp;
}
}
}
</script>
<style scoped> // scoped 样式只在当前文件有效
ul{
padding: 0;
margin: 0;
list-style: none;
}
</style>
mynav.vue
<template>
<div class="box">
<ul>
<li v-for="(x,index) in nav" :class="{'red':index==cur}" @click="click(index)">{{x}}</li>
</ul>
<div v-for="(x,index) in cont" :class="{'curdiv':index==cur}">{{x}}</div>
</div>
</template>
<script>
export default {
props:["titles","contents"],
computed:{
nav(){
return this.titles.split(",")
},
cont(){
return this.contents.split(",")
}
},
data(){
return{
cur:0
}
},
methods:{
click(index){
this.cur=index;
}
}
}
</script>
<style scoped>
*{margin: 0;padding: 0;}
#app{
margin: 50px auto;
width: 500px;
}
ul{
list-style: none;
}
ul li{
float: left;
width: 60px;
text-align: center;
cursor: pointer;
line-height: 40px;
}
.red{
color: red;
}
.box div{
display: none;
text-align: center;
font-size: 40px;
line-height: 200px;
border: 1px solid #333;
width: 500px;
}
.box .curdiv{
clear: both;
display: block;
}
</style>
myfooter.vue
<template>
<p>页脚</p>
</template>
<script>
</script>
<style>
</style>