zoukankan      html  css  js  c++  java
  • vue.js路由

    1:编写router.js
     
    import Router from "vue-router"
    import Vue from "vue"
    import router from "./router/router.vue" // 导入
    import component from "./component/component.vue"
    import databinding from "./databinding/databinding.vue"
    import directive from "./directive/directive.vue"
    import eventhanding from "./eventhanding/eventhanding.vue"
    import stylebinding from "./stylebinding/stylebinding.vue"
    import home from "./home.vue"
    Vue.use(Router) // 引用
    export default new Router({
    linkActiveClass: 'active',
    routes: [
    { path: '/component', component: component },
    { path: '/databinding', component: databinding },
    { path: '/directive', component: directive },
    { path: '/eventhanding', component: eventhanding },
    { path: '/stylebinding', component: stylebinding },
    { path: '/router/:userId', component: router }, // 路由传值
    { path: '/*', component: home }, // 找不到路由时跳转到这,一般设置为首页
    ]
    })
    2:在main.js中注册router
     
    import Vue from 'vue'
    import ElementUI from 'element-ui'
    import 'element-ui/lib/theme-chalk/index.css'
    import App from './App.vue'
    import router from './router.js' //

    Vue.use(ElementUI)

    new Vue({
    el: '#app',
    router, // 注册router
    render: h => h(App)
    })
    3:路由跳转传参
     
    <el-button class="btnstyle" @click="routerClick">路由</el-button>
    routerClick() { // 传入跳转的参数
    const userId = 123456;
    this.$router.push({
    path: `/router/${userId}`
    });
    console.log("点击路由按钮");
    },
     
    4:接收路由参数
     
    data() {
    return {
    text: this.$route.params.userId
    };
    },
  • 相关阅读:
    iframe跨域
    jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
    jQuery中this与$(this)的区别
    div层调整zindex属性无效原因分析及解决方法
    The local variable......been initialized
    equals方法的重写
    eclipse快捷键
    JAVA中几个常用的方法
    Java基础4(方法基础和一维数组)
    Java基础3笔记
  • 原文地址:https://www.cnblogs.com/husfBK/p/8967678.html
Copyright © 2011-2022 走看看