解決使用vue.js路由后失效的問題
更新時間:2018年03月17日 15:32:56 作者:Eve慕
下面小編就為大家分享一篇解決使用vue.js路由后失效的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
新學(xué)了vue.js中的路由 在之前寫的vue的demo上加上了簡單的路由例子(來自vue-router 2),但是加上點擊后只有地址欄變化,內(nèi)容并不變.且之前用jquery寫的一些效果也失效了.最后找到原因是因為同一個id被啟動了兩次(第一次是之前使用vue組件時啟動的,另外一個是路由時啟動的)
附上部分代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- 引入樣式 -->
<link rel="stylesheet" rel="external nofollow" >
</head>
<style>
body {
margin: 0;
padding: 0;
}
.logo {
width: 166.65px;
height: 60px;
position: absolute;
}
.el-menu-demo {
margin-left: 166.65px;
}
.tac {
width: 500px;
}
.bar2,.bar3{
display: none;
}
</style>
<body>
<div id="top-menu">
<div class="logo">
<img src="baidu.gif" alt="">
</div>
<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
<el-menu-item index="1" class="nav1">基本資料</el-menu-item>
<el-menu-item index="2" class="nav2">培養(yǎng)信息</el-menu-item>
<el-menu-item index="3" class="nav3">考核相關(guān)</el-menu-item>
<el-menu-item index="4" class="nav4">清算</el-menu-item>
</el-menu>
</div>
<div id="left-menu">
<el-row class="tac">
<!-- 基本資料-->
<el-col :span="8" class="bar1">
<el-menu mode="vertical" default-active="1" class="el-menu-vertical-demo" @select="handleSelect" theme="dark">
<el-menu-item-group title="個人資料">
<!-- 路由鏈接添加處 -->
<router-link to = "/information"><el-menu-item index="1"><i class="el-icon-message"></i>基本信息</el-menu-item></router-link>
<el-menu-item index="2"><i class="el-icon-message"></i>修改密碼</el-menu-item>
</el-menu-item-group>
<el-menu-item-group title="會員資料">
<router-link to = "/list"><el-menu-item index="3"><i class="el-icon-message"></i>會員信息</el-menu-item></router-link>
</el-menu-item-group>
<el-menu-item-group title="小組資料">
<el-menu-item index="4"><i class="el-icon-message"></i>小組信息</el-menu-item>
</el-menu-item-group>
</el-menu>
</el-col>
</el-row>
<!-- 路由內(nèi)容顯示 -->
<div class = "content">
<router-view></router-view>
</div>
</div>
</body>
<!-- 先引入 Vue -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<!-- 引入組件庫 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".nav1").click(function(){
$(".bar1").show().siblings().hide();
})
$(".nav2").click(function(){
$(".bar2").show().siblings().hide();
})
$(".nav3").click(function(){
$(".bar3").show().siblings().hide();
})
})
</script>
<script type="text/javascript">
//vue組件部分
var Main = {
data() {
return {
activeIndex: '1'
};
},
methods: {
handleSelect(key, keyPath) {
/*console.log(key, keyPath);*/
}
}
}
//vue路由部分
const Information = {template:'<div>foo</div>'}
const List = {template:'<div>list</div>'}
const routes = [
{path:'/information',component:Information},
{path:'/list',component:List}]
const router = new VueRouter({
routes
})
const app = new Vue({
router
}).$mount('#left-menu') //路由 啟動應(yīng)用
var Ctor = Vue.extend(Main)
new Ctor().$mount('#top-menu')
//主要就是下面這條語句多余 這是寫組件時啟動應(yīng)用所用的語句
//new Ctor().$mount('#left-menu')
</script>
</html>
以上這篇解決使用vue.js路由后失效的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue中v-if和v-for一起使用的弊端及解決辦法(同時使用 v-if 和 v-for不
當(dāng) v-if 和 v-for 同時存在于一個元素上的時候,v-if 會首先被執(zhí)行,這篇文章主要介紹了vue中v-if和v-for一起使用的弊端及解決辦法,需要的朋友可以參考下2023-07-07
解決element-ui的el-select選擇器的@blur事件失效的坑
這篇文章主要介紹了解決element-ui的el-select選擇器的@blur事件失效的坑,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
vue中this.$router.push()路由傳值和獲取的兩種常見方法匯總
這篇文章主要介紹了vue中this.$router.push()路由傳值和獲取的兩種常見方法,本文結(jié)合示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-12-12

