onReady() { uni.getProvider({ service: 'share', success: (e) => { console.log(e); let data = [] for (let i = 0; i < e.provider.length; i++) { switch (e.provider[i]) { case 'weixin': data.push({ name: '微信好友', icon:"icon-weixin", color:"bg-success", id: 'weixin', sort:0 }) data.push({ name: '朋友圈', icon:"icon-huati", color:"bg-dark", id: 'weixin', type:'WXSenceTimeline', sort:1 }) break; case 'sinaweibo': data.push({ name: '新浪微博', icon:"icon-xinlangweibo", color:"bg-danger", id: 'sinaweibo', sort:2 }) break; case 'qq': data.push({ name: 'QQ好友', icon:"icon-QQ", color:"bg-primary", id: 'qq', sort:3 }) break; default: break; } } this.providerList = data.sort((x,y) => { return x.sort - y.sort }); }, fail: (e) => { uni.showModal({ content:'获取分享通道失败', showCancel:false }) } }); },怎么不显示providerList数据
时间: 2024-01-22 19:20:32 浏览: 74
可能是因为在onReady()函数中,你只是对providerList进行了赋值,但没有将其传递到页面上显示。你需要在页面中使用v-for指令,遍历providerList数组,并将每个数组项的数据展示出来。例如:
```
<template>
<div>
<div v-for="provider in providerList" :key="provider.id">
<span>{{provider.name}}</span>
<span>{{provider.icon}}</span>
<span>{{provider.color}}</span>
<span>{{provider.id}}</span>
<span>{{provider.type}}</span>
<span>{{provider.sort}}</span>
</div>
</div>
</template>
```
请注意,此示例仅将每个数组项的数据显示在页面上。你可能需要根据需要进行修改,以在页面上正确地显示这些数据。
相关问题
uniapp分享 onReady() { uni.getProvider({ service: 'share', success: (e) => {怎么不显示图标
可能是因为您没有正确配置分享图标的路径。请确保您在uni-app项目中已经将分享图标文件放置在正确的位置,并在页面中正确地设置分享图标路径。
您可以尝试使用绝对路径来设置分享图标路径,例如:
```
onReady() {
uni.getProvider({
service: 'share',
success: (e) => {
if (e.provider[0] === 'weixin') {
uni.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
uni.updateShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
uni.onShareAppMessage(() => {
return {
title: '分享标题',
path: '/pages/index/index',
imageUrl: '/static/share-icon.png' // 使用相对路径可能会出现问题,建议使用绝对路径
}
})
}
}
})
}
```
请注意,图片路径应该是相对于您的项目根目录的。如果您使用了static文件夹存储分享图标,请确保您已正确设置路径。
如果问题仍然存在,请检查您的图片是否存在并且路径是否正确。
onReady() { let view = uni.createSelectorQuery().select(".homedata"); view.boundingClientRect(data => { console.log(data); // this.clentHeight = data.height; }).exec(); },为什么data为null
在你提供的代码中,可以看到你使用了 `uni.createSelectorQuery()` 方法来创建一个选择器查询实例,并使用 `select()` 方法选择了一个类名为 "homedata" 的元素。
根据你的描述,当执行 `boundingClientRect()` 方法时,`data` 参数返回了 null。这可能是因为选择器查询实例还没有执行 `exec()` 方法来触发查询操作。
`uni.createSelectorQuery()` 方法返回的是一个选择器查询实例,你需要调用 `exec()` 方法来执行查询操作并获取结果。在你的代码中,你需要将 `.exec()` 方法链式调用到 `select()` 方法之后,如下所示:
```javascript
onReady() {
uni.createSelectorQuery().select(".homedata").boundingClientRect(data => {
console.log(data);
// this.clentHeight = data.height;
}).exec();
}
```
确保在调用 `boundingClientRect()` 方法之前,先调用了 `exec()` 方法来触发查询操作。这样应该能够正确获取到元素的 boundingClientRect 数据。如果仍然返回 null,请检查选择器是否正确,元素是否已加载和渲染完成。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)