weex vue 路由 .vue页面间跳转

最简单的页面跳转,以下是按照weex官网安装出来的目录结构:


一、首页  foo.vue 页面(类似一个容器)

<template>

     <div class="wrapper">

          <router-view></router-view>

      </div>

</template>

二、修改 app.js 页面

import foo from './src/foo.vue'

import router from './src/router.js'  //导入路由文件

foo.el='#root'  

foo.router=router  //给根组件设置路由

export default new Vue(foo);  //穿件vue对象

router.push('home')  //指定一个路由入口(初始显示的页面内容)

三、src目录下新建 router.js 文件

//导入模块

import VueRouter from 'vue-router'

import Vue from 'vue'

//导入使用的组件

import home from'./home.vue'

import messages from'./messages.vue'


Vue.use(VueRouter)

//创建路由对象

export default newVueRouter({

     //mode: 'abstract',//weex 中只能使用 abstract 类型 默认可以不写 系统会自动设置为abstract

     routes:[

        {path:'/home',component: home},

        {path:'/messages',component:messages}

      ]

})

四、src新建home.vue

<template>

    <div>

        <text class="button" @click="jump('messages')"> 跳转至messages页面 </text>

    </div>

</template>

<script>

      export default {

           methods:{

                jump:function (e) {

                        this.$router.push(e);

                 }

            }

     }

</script>

五、src新建messages.vue

<template>

    <div>

        <text class="button" @click="goback()">返回</text>

        <text>messages页面</text>

     </div>

</template>

<script>

export default{

    methods:{

        goback:function(){

             this.$router.go(-1)

         }

    }

}

</script>

如图+最后目录:


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • 这篇笔记主要包含 Vue 2 不同于 Vue 1 或者特有的内容,还有我对于 Vue 1.0 印象不深的内容。关于...
    云之外阅读 10,454评论 0 29
  • Vue-router学习指南 日记:本文按照vue-router官网的知识结合例子进行分析和讲解,搭建工具(vue...
    sunny519111阅读 5,305评论 0 6
  • 响应式布局的理解 响应式开发目的是一套代码可以在多种终端运行,适应不同屏幕的大小,其原理是运用媒体查询,在不同屏幕...
    懒猫_6500阅读 4,166评论 0 0
  • 《糟糕,身上长条纹了!》是大卫·香农著名的代表作,这本书用超现实的经历隐喻孩子成长过程中不断面临的心理认同挑战——...
    晨光微晓阅读 7,184评论 2 5