import Vue from 'vue'
import App from './App.vue' import Home from './components/Home.vue'
import News from './components/News.vue' import VueRouter from 'vue-router'
Vue.use(VueRouter) const routes = [
{ path: '/home', component: Home },
{ path: '/news', component: News,name:'newss' },
{ path: '*', redirect: '/home' }
] const router = new VueRouter({ routes,mode:'history' }); new Vue({
el: '#app',
router,
render: h => h(App)
})
<template>
<div id="home">
我是Home组件
<button @click="TiaoZhuan()">跳转到News【path】</button>
<button @click="TiaoZhuanName()">跳转到News【name】</button>
</div>
</template> <script>
export default{
methods:{
TiaoZhuan(){
this.$router.push({path:'news'})
},
TiaoZhuanName(){
this.$router.push({name:'newss'})
}
}
}
</script>
<template>
<div id="news">
我是News组件
</div>
</template>

Vue 编程式导航,路由history模式的更多相关文章

  1. Vue 路由的编程式导航与history模式

    编程式导航 注意:官方文档写错了 通过javascript跳转 //第一种跳转方式 // this.$router.push({ path: 'news' }) // this.$router.pus ...

  2. vue编程式导航,命名路由

    //使用 window.location.href 的形式,叫做 编程式导航 绑定事件的形式 <template> <div class="goods-item" ...

  3. vue编程式导航

    vue项目中使用到了组件间传值,通过路由跳转实现从产品页进入产品详情页查看功能. 使用了this.$router.push(编程式导航) product页面中:因为只需要遮住产品列表页来显示产品详情页 ...

  4. 编程式导航路由跳转到当前路由(参数不变), 多次执行会抛出NavigationDuplicated的警告错误?

    注意:编程式导航(push|replace)才会有这种情况的异常,声明式导航是没有这种问题,因为声明式导航内部已经解决这种问题. 这种异常,对于程序没有任何影响的. 为什么会出现这种现象: 由于vue ...

  5. Vue 编程式导航(通过js跳转页面)以及路由hash模式和history模式

    第一种方法: this.$router.push({path:'shopcontent?aid=3'}   第二种方法   this.$router.push({name:'news'}} 通过在ma ...

  6. Vue路由编程式导航以及hash模式

    import Vue from 'vue'; import App from './App.vue'; //引入公共的scss 注意:创建项目的时候必须用scss import './assets/c ...

  7. vue 编程式导航

    // 命名的路由(这里的name为路由中定义的name名称) this.$router.push({ name: 'user', params: { userId: '123' }}) // 带查询参 ...

  8. VueRouter爬坑第四篇-命名路由、编程式导航

    VueRouter系列的文章示例编写时,项目是使用vue-cli脚手架搭建. 项目搭建的步骤和项目目录专门写了一篇文章:点击这里进行传送 后续VueRouter系列的文章的示例编写均基于该项目环境. ...

  9. vue动态路由传值以及get传值及编程式导航

    1.动态路由传值 1.配置路由处 { path: '/content/:id', component: Content }, // 动态路由 2.对应页面传值 <router-link :to= ...

随机推荐

  1. 好用的一个object c 宏

    好用的一个object c 宏 from https://github.com/justzt/ios-helper/blob/master/Macro.h // // Macro.h // Photo ...

  2. 一个简单的Python多线程

    首先对一段普通的代码进行测试 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import time def RunThrea ...

  3. php命令执行

    php命令执行通过函来执行外部应用程序,函数有shell_exec(),exec(),system(),passthru() <?php $i = $_GET['cmd']; echo exec ...

  4. 基本的Ceph性能测试工具和方法

    测试环境 1. 测试准备 1.1 磁盘读写性能 1.1.1 单个 OSD 磁盘写性能,大概 165MB/s. root@ceph1:~# echo 3 > /proc/sys/vm/drop_c ...

  5. java rest jax-rs 漫谈

    rest是什么 REST是英文RepresentationalState Transfer 的缩写,有中文翻译为“具象状态传输”.REST 这个术语是由 RoyFielding 在他的博士论文< ...

  6. Python 面向对象的进阶

    类的成员 类的成员可以分为三大类 :  字段 , 方法 和  属性 注 :  所有的成员中,只有普通字段的内容保存对象中,  即 : 根据此类创建了对象,在内存就有多少个普通字段.  而其他的成员,则 ...

  7. asp:GridView控件的使用

    使用asp:GridView显示一个统计的表格 cs样式: <style>        table.gridview_m        {            border-colla ...

  8. Vulkan Tutorial 10 图形管线

    操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 Introduction 通过接下来的章节,我们将会开启有关图形管线的话题,通过对图 ...

  9. 【原】Zookeeper 概述 + 官网 Overview 翻译

    分布式应用 分布式应用 distributed application可以在给定时间(同时)在网络中的多个系统上运行,通过协调它们以快速有效的方式完成特定任务. (a), (b): a distrib ...

  10. java Web servlet简介及其生命周期

    Servlet(Server Applet)是Java Servlet的简称,称为小服务程序或服务连接器,用Java编写的服务器端程序,主要功能在于交互式地浏览和修改数据,生成动态Web内容. 我们可 ...