npm install -g vue-cli
cd vue_test_project //进入vue_test_project目录下 vue init webpack vuedemo //在vue_test_project目录下创建一个vuedemo工程
cd vuedemo npm install
npm run dev
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h2>Essential Links</h2>
<div class="btn">
<router-link :to="{name:'content',params:{differId:'con1'}}">内容按钮1</router-link>
<router-link :to="{name:'content',params:{differId:'con2'}}">内容按钮2</router-link>
</div>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import content from '@/components/conDetail'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld,
children:[
{name:'content',path:'content/:differId',component:content}
]
}
]
})
<template>
<div class="same">
这个是相同的内容
<div class="conlist">
<template v-for="item in items">
<p>{{item.con}}</p>
</template>
</div>
</div>
</template>
<script>
export default {
name: 'conDetail',
data () {
return {
msg: '',
differIdType:'',
conlist:[
{'con':'这是第一个内容按钮的内容1'},
{'con':'这是第一个内容按钮的内容2'}
],
items:[],
}
},
mounted(){
this.differIdType = this.$route.params.differId == 'con1' ? '0' : '1';
if(this.differIdType == 0){
this.items = this.conlist;
}else{
this.items = [];
}
},
watch:{
$route:function(to,from){
this.differIdType = to.params.differId == 'con1' ? '0' : '1';
if(this.differIdType == 0){
this.items = this.conlist;
}else{
this.items = [];
}
}
}
}
</script>
<style>
</style>
const User = {
template: '...',
watch: {
'$route' (to, from) {
// 对路由变化作出响应...
}
}
}
const User = {
template: '...',
beforeRouteUpdate (to, from, next) {
// react to route changes...
// don't forget to call next()
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有