美文网首页
[每天进步一点点~] uni-app 页面跳转及传值

[每天进步一点点~] uni-app 页面跳转及传值

作者: WYL_99 | 来源:发表于2020-09-09 20:27 被阅读0次

1. v-for

在uni-app开发项目时,若使用 v-for 循环遍历数组,注意要绑定 key ,否则运行到别的平台会报错。

2.页面跳转传值(传的是数组或对象)和接收值

传值的页面,要先把值使用 JSON.stringify(值)转化后再传
接收值的页面,要先使用 JSON.parse(接收的值)转化

index.vue 文件

<template>
    <view class="content">
        <button @click="toDetail">跳到详情页1</button>
        <button @click="toDetail2">跳到详情页2</button>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                id: 2,
                infolist: {
                    name:'张三',
                    age: 18,
                    sex: '男'
                },
            }
        },
        onLoad() {

        },
        methods: {
            toDetail() {
                var list = JSON.stringify(this.infolist)
                uni.navigateTo({
                    url:'/pages/index/detail?list=' + list
                })
            },
            toDetail2() {
                uni.navigateTo({
                    url:'/pages/index/detail2?id=' + this.id
                })
            }
        }
    }
</script>

<style>
    .content {
        margin: 50px auto;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
</style>

detail.vue文件

<template>
    <view class="content">
        <view>id:{{id}}</view>
        <view>姓名:{{name}}</view>
        <view>年龄:{{age}}</view>
        <view>性别:{{sex}}</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                infolist: {},
                id: 1,
                name:'依依',
                age: 20,
                sex: '女',
            }
        },
        onLoad(options) {
            // console.log(options);
            this.infolist = JSON.parse(options.list)
            this.name = this.infolist.name
            this.age = this.infolist.age
            this.sex = this.infolist.sex            
        }
    }
</script>

<style lang="scss" scoped>
    .content {
        display: flex;
        flex-direction: column;
        
    }
</style>

detail2.vue文件

<template>
    <view class="content">
        <view>id:{{id}}</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                id: 1,
            }
        },
        onLoad(options) {
            // console.log(options);
            this.id = options.id
        }
    }
</script>

<style lang="scss" scoped>
    .content {
        display: flex;
        flex-direction: column;
        
    }
</style>

相关文章

  • [每天进步一点点~] uni-app 页面跳转及传值

    1. v-for 在uni-app开发项目时,若使用 v-for 循环遍历数组,注意要绑定 key ,否则运行到别...

  • 1.23 ionic3——页面跳转及传值

    我一般用两种方法进行页面的跳转与传值第一种(1)跳转 (2)跳转及传值 在B页面构造函数中接收 第二种列表中我喜欢...

  • ionic关于跳转那些事

    简单介绍一下跳转页面,和页面传值 引入 页面跳转并传值 返回上一页 请求接口失败或者成功返回页面 如果需要返回是传入值

  • swift 闭包传值

    场景:A页面跳转到B页面,B页面返回到A页面,(B页面给A页面传值) B页面逻辑:创建block,声明变量,传值 ...

  • 微信小程序几种常用的跳转方式并传值

    第一种:通过链接传值(跳转页面传值) 第二种:跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 第...

  • swift 代理传值

    场景:A页面跳转到B页面,B页面返回到A页面,(B页面给A页面传值) B页面逻辑:创建协议,声明变量,传值 A页面...

  • 金蝶kingdee mbos移动轻应用开发脚本参考

    前端事件脚本 1.手动调用提交校验页面字段必填项方法: 2.mbos内页面跳转以及传值: 3.跳转后页面接收传值:...

  • mpvue页面跳转及传值

    vue中 使用 vue-router 来进行路由跳转的。mpvue中只能通过以下几种方式跳转:(1).a 标签 (...

  • query与params的页面传值

    先简单记录页面传值, 还没完全弄懂其中的原理先配置路径跳转 params data传参 params传参 跳转页面...

  • iOS五种页面传值方式

    方式一:属性传值 A页面的值跳转到B页面之后把值传给B页面,只需要在.h文件定义属性,A页面再跳转之前赋值给B页面...

网友评论

      本文标题:[每天进步一点点~] uni-app 页面跳转及传值

      本文链接:https://www.haomeiwen.com/subject/fsdyektx.html