当前位置: 首页 > news >正文

手机ftp传网站文件可以免费推广的平台

手机ftp传网站文件,可以免费推广的平台,自建网站怎么做优化,西安医院网站建设目录 一、传递方式1. URL传参2. Storage传参3. Vuex传参4.api传参eventChannel 二、接受方式1. URL传参2. Storage传参3. Vuex传参4.api传参eventChannel 三、使用案例四.提醒 在uniapp中,页面传参是非常常见的需求。本文将详细讲解uniapp中页面传参的传递方式和接受…

目录

    • 一、传递方式
      • 1. URL传参
      • 2. Storage传参
      • 3. Vuex传参
      • 4.api传参eventChannel
    • 二、接受方式
      • 1. URL传参
      • 2. Storage传参
      • 3. Vuex传参
      • 4.api传参eventChannel
    • 三、使用案例
    • 四.提醒

在uniapp中,页面传参是非常常见的需求。本文将详细讲解uniapp中页面传参的传递方式和接受方式,以及使用案例,同时附上代码注释。

一、传递方式

1. URL传参

URL传参是一种比较简单的传递方式,它是通过URL地址来传递参数的。我们可以在URL地址后面加上参数,例如:

<uni-button @click="goToDetail">跳转到详情页</uni-button>//编程式传参  比较常用
<navigator url="/pages/detail/detail?id=123">跳转到详情页</navigator>//标签传参
// 跳转到详情页,并传递id参数
goToDetail() {uni.navigateTo({url: '/pages/detail/detail?id=123'})
}

在接收页面中,我们可以通过this.$route.query来获取传递的参数:

export default {onLoad() {console.log(this.$route.query.id) // 输出:123}
}

对于微信小程序 this.$ route.query.id 可能不能使用 因为微信小程序不识别 this.$ route
而替代方案
不使用this.$ route 使用 onload传参

onLoad(getData) {//getData就是参数对象  兼用微信小程序console.log(getData.id);		
}

2. Storage传参

Storage传参是通过uni-app提供的Storage API来传递参数的。我们可以在跳转之前将参数存储到Storage中,然后在接收页面中获取:

<uni-button @click="goToDetail">跳转到详情页</uni-button>// 跳转到详情页,并将id参数存储到Storage中
goToDetail() {uni.setStorageSync('id', 123)uni.navigateTo({url: '/pages/detail/detail'})
}

在接收页面中,我们可以通过uni.getStorageSync来获取存储的参数:

export default {onLoad() {console.log(uni.getStorageSync('id')) // 输出:123}
}

3. Vuex传参

Vuex传参是通过uni-app提供的Vuex API来传递参数的。我们可以在跳转之前将参数存储到Vuex中,然后在接收页面中获取:

<uni-button @click="goToDetail">跳转到详情页</uni-button>// 跳转到详情页,并将id参数存储到Vuex中
goToDetail() {uni.$emit('setId', 123)uni.navigateTo({url: '/pages/detail/detail'})
}

在Vuex中,我们可以定义一个state来存储参数:

const store = new Vuex.Store({state: {id: ''},mutations: {setId(state, id) {state.id = id}}
})

在接收页面中,我们可以通过mapState来获取存储的参数:

import { mapState } from 'vuex'export default {computed: {...mapState(['id'])},onLoad() {console.log(this.id) // 输出:123}
}

4.api传参eventChannel

api传参是通过uni-app提供的API来传递参数的。我们可以在跳转之前将参数存储到options中,例如:

<uni-button @click="goToDetail">跳转到详情页</uni-button>// 跳转到详情页,并传递id参数
goToDetail() {uni.navigateTo({url: '/pages/detail/detail',success: (res) => {res.eventChannel.emit('acceptDataFromOpenerPage', { id: 123 })}})
}

在这个例子中,我们使用了eventChannel来传递参数。我们在跳转之前,通过success回调函数来获取eventChannel,然后通过emit方法来传递参数。

在api传参的方式中,我们可以通过uni.on来监听传递的参数:

export default {onLoad() {const eventChannel = this.getOpenerEventChannel()eventChannel.on('acceptDataFromOpenerPage', (data) => {console.log(data.id) // 输出:123})}
}

在这个例子中,我们通过getOpenerEventChannel方法来获取eventChannel,然后通过on方法来监听传递的参数。

二、接受方式

1. URL传参

在URL传参的方式中,我们可以通过this.$route.query来获取传递的参数:

export default {onLoad() {console.log(this.$route.query.id) // 输出:123}
}

2. Storage传参

在Storage传参的方式中,我们可以通过uni.getStorageSync来获取存储的参数:

export default {onLoad() {console.log(uni.getStorageSync('id')) // 输出:123}
}

3. Vuex传参

在Vuex传参的方式中,我们可以通过mapState来获取存储的参数:

import { mapState } from 'vuex'export default {computed: {...mapState(['id'])},onLoad() {console.log(this.id) // 输出:123}
}

4.api传参eventChannel

在api传参的方式中,我们可以通过uni.on来监听传递的参数:

export default {onLoad() {const eventChannel = this.getOpenerEventChannel()eventChannel.on('acceptDataFromOpenerPage', (data) => {console.log(data.id) // 输出:123})}
}

在这个例子中,我们通过getOpenerEventChannel方法来获取eventChannel,然后通过on方法来监听传递的参数。

三、使用案例

下面是一个完整的使用案例,包括传递和接收参数的方式:

// pages/index/index.vue
<template><view><uni-button @click="goToDetail">跳转到详情页</uni-button></view>
</template><script>
export default {methods: {goToDetail() {// URL传参// uni.navigateTo({//   url: '/pages/detail/detail?id=123'// })// Storage传参// uni.setStorageSync('id', 123)// uni.navigateTo({//   url: '/pages/detail/detail'// })// Vuex传参uni.$emit('setId', 123)uni.navigateTo({url: '/pages/detail/detail'})}}
}
</script>// pages/detail/detail.vue
<template><view><text>{{ id }}</text></view>
</template><script>
import { mapState } from 'vuex'export default {computed: {...mapState(['id'])},onLoad() {// URL传参// console.log(this.$route.query.id)// Storage传参// console.log(uni.getStorageSync('id'))// Vuex传参// console.log(this.id)}
}
</script>// store/index.js
import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)const store = new Vuex.Store({state: {id: ''},mutations: {setId(state, id) {state.id = id}}
})uni.$on('setId', id => {store.commit('setId', id)
})export default store

以上就是uniapp中页面传参的传递方式和接受方式的详细讲解,以及使用案例和代码注释。希望对大家有所帮助!

四.提醒

以上的页面传参方式中

  1. URL传参
  2. Storage传参
    比较常用 可以满足大家的开发需求

另外的传参方式 看场景和需求在做处理
希望对你有所帮助

http://www.hkea.cn/news/315444/

相关文章:

  • 织梦做的网站首页出现空白网页平台做个业务推广
  • 备案做电影网站吗yandx引擎入口
  • 网站双倍浮动百度账号登陆入口
  • 聊城市网站建设网站推广排名
  • 帝国新闻网站模板百度seo推广怎么做
  • 预约做港澳证的网站网站排名在线优化工具
  • 罗湖实惠的网站建设费用成都官网seo厂家
  • 建设部官方网站有哪些优帮云排名优化
  • 天津做网站找谁新东方在线教育平台官网
  • 南宁做网站在哪了日本预测比分
  • 咋样查看网站用什么编程语言做的9个广州seo推广神技
  • 网站链接太多怎么做网站地图谷歌广告
  • 网站关键词更新临汾网络推广
  • 个人做网站靠什么盈利免费网站建设模板
  • 网站开发 打标签aso优化怎么做
  • 教育校园网站建设方案seo每天一贴
  • 怎么看网站的建设时间推广公司品牌
  • 营销型网站有什么特点英语培训机构
  • 学院网站的系统建设方式宝鸡网站seo
  • 网站客户端怎么做的百度一下了你就知道官网
  • 有什么推广方法优化大师电脑版官方
  • 自己做网站的服务器上海网站建设公司排名
  • 跳蛋塞逼做多的视频网站百度广告联盟官网
  • 房地产网站开发文档企业查询
  • 做emu对网站有什么要求十大免费无代码开发软件
  • 扬州专业做网站做关键词优化
  • 宿州网站建设贰聚思诚信网站服务器
  • 用照片做模板下载网站好百度爱采购官方网站
  • 微网站建设套餐网络营销是做什么的
  • 徐州有哪些做网站苏州网站建设费用