SPA單頁應(yīng)用:一級路由

一個vue的單頁應(yīng)用的腳手架程序構(gòu)建

  • 命令行先進(jìn)入某個目錄如D:\VueStudy

  • 創(chuàng)建項目: vue init webpack demo

  • 進(jìn)入demo目錄安裝依賴:npm install

  • 修改config目錄下index.js的dev端口為80
    5.運(yùn)行:npm run dev,打開http://localhost,看到Vue主頁logo即成功

    image

App

<template>
<div id="app" class="container">
<div class="header">
<router-link to="/" class="nav-item">首頁</router-link>
<router-link to="/message" class="nav-item">消息</router-link>
</div>
<div class="content">
<router-view></router-view>
</div>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style>
.container{
width: 80%;
margin: 0 auto;
height: 400px;
}
.header{
display: flex;
height: 100px;
background-color: darkcyan;
font-size: 20px;
padding-left: 20px;
align-items: center;
}
.nav-item{
margin-right: 20px;
}
.content{
background-color: #2c3e50;
color: #ffffff;
}
</style>

Massage.vue

<template>
<div class="container">
<h2>消息</h2>
{{ msg }}
</div>
</template>
<script>
export default {
name: 'Index',
data() {
return {
msg: '消息'
};
}
};
</script>
<style scoped></style>

index.vue

<template>
<div class="container">
<h2>首頁</h2>
{{msg}}
</div>
</template>
<script>
export default{
name:'Index',
data(){
return{
msg:'首頁'
};
}
};
</script>
<style scoped>
</style>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容