i***@live.cn
i***@live.cn
  • 发布:2023-06-15 19:32
  • 更新:2023-06-16 10:49
  • 阅读:2175

vue3 方式开发,如何获取url参数

分类:uni-app

按照小程序的方式,是这样获取url 参数的

export default {  
  onLoad(options) {  
    this.productId = options.productId;  
    this.fetchData();  
  }  
}

请问,如果用 vue3 的 setup 方式该如何写?

2023-06-15 19:32 负责人:无 分享
已邀请:
赵永强

赵永强 - 前端老菜鸟

<script setup>  
import { onLoad } from '@dcloudio/uni-app';  

//第一种  
onLoad((options)=>{  
console.log(options)  
})  
//第二种  
  // 页面可以通过定义 props 来直接接收 url 传入的参数  
  // 如:uni.navigateTo({ url: '/pages/index/index?id=10' })  
  const props = defineProps({  
    id: String,  
  });  
  console.log("id=" + props.id); // id=10  

</script>  
昭昭L

昭昭L - 开心就好

const route = useRoute()
const id = route.value.params.id

该问题目前已经被锁定, 无法添加新回复