<template>
<view class="container">
<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" :options="options" :where="sWhere"
:collection="collectionList" field="title,content,excerpt,publish_date,last_modify_date,skip_mode,skip_url,down_url"
:getone="true" loadtime="manual" @load="handleLoad">
<view v-if="error">{{error.message}}</view>
<view v-else-if="loading">
<uni-load-more :contentText="loadMore" status="loading"></uni-load-more>
</view>
<view v-else-if="data">
<view>
<bctos-rich-text :nodes="data.content"></bctos-rich-text>
</view>
<view class="margin-top-sm">
<uni-card>
<view class="flex flex-direction-row justify-center align-center">
<button class="down_button" type="primary" @click="downLoadFile(data.down_url.url)">下载</button>
</view>
</uni-card>
</view>
</view>
</unicloud-db>
</view>
</template>
<script>
const db = uniCloud.database()
export default {
data() {
return {
queryWhere: '',
collectionList: "weixiu-downdrive",
sWhere: "",
loadMore: {
contentdown: '',
contentrefresh: '',
contentnomore: ''
}
}
},
onLoad(e) {
this._id = e.id
if (this._id) {
this.sWhere = '_id=="' + this._id + '"'
}
},
onReady() {
this.$nextTick(()=>{
this.$refs.udb.loadData();
})
},
methods: {
handleLoad(data){
console.log(data)
},
downLoadFile(url){
uni.downloadFile({
url: url,
fail: function(err) {
console.log(err)
uni.showToast({
title: err,
icon: 'error'
})
},
success: function(res) {
console.log('下载回调',res)
uni.showModal({
title: '成功',
content:'下载成功',
showCancel:false
})
}
})
}
}
}
</script>
- 发布:2023-03-31 20:10
- 更新:2023-03-31 20:37
- 阅读:206
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 22H2
HBuilderX类型: 正式
HBuilderX版本号: 3.7.9
第三方开发者工具版本号: 1.06.2301160
基础库版本号: 2.25.3
项目创建方式: HBuilderX
App下载地址或H5⽹址: 暂无
示例代码:
操作步骤:
小程序 调试报错如下:
TypeError: Cannot read property 'down_url' of undefined
at getTarget (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9798)
at getTarget (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9798)
at VueComponent.Vue.__get_value (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9910)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2737
at Array.forEach (<anonymous>)
at processEventExtra (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2722)
at processEventArgs (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2775)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2864
at Array.forEach (<anonymous>)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2840(env: Windows,mp,1.06.2301160; lib: 2.25.3)
报错代码所在行就是这里
<view class="flex flex-direction-row justify-center align-center">
<button class="down_button" type="primary" @click="downLoadFile(data.down_url.url)">下载</button>
</view>
小程序 调试报错如下:
TypeError: Cannot read property 'down_url' of undefined
at getTarget (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9798)
at getTarget (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9798)
at VueComponent.Vue.__get_value (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9910)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2737
at Array.forEach (<anonymous>)
at processEventExtra (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2722)
at processEventArgs (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2775)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2864
at Array.forEach (<anonymous>)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2840(env: Windows,mp,1.06.2301160; lib: 2.25.3)
报错代码所在行就是这里
<view class="flex flex-direction-row justify-center align-center">
<button class="down_button" type="primary" @click="downLoadFile(data.down_url.url)">下载</button>
</view>
预期结果:
unicloud-db组件下
...
@click="downLoadFile(data.down_url.url)"
可以正常取到值
unicloud-db组件下
...
@click="downLoadFile(data.down_url.url)"
可以正常取到值
实际结果:
unicloud-db组件下
...
@click="downLoadFile(data.down_url.url)"
报错data为undefined
unicloud-db组件下
...
@click="downLoadFile(data.down_url.url)"
报错data为undefined
bug描述:
在unicloud-db组件下,嵌套使用一些uni-ui官方扩展组件时,在组件内部调用data会报data为undefined
小程序 调试报错如下:
TypeError: Cannot read property 'down_url' of undefined
at getTarget (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9798)
at getTarget (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9798)
at VueComponent.Vue.__get_value (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:9910)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2737
at Array.forEach (<anonymous>)
at processEventExtra (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2722)
at processEventArgs (vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2775)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2864
at Array.forEach (<anonymous>)
at vendor.js?t=wechat&s=1680263306155&v=b50d8555d1416ef5747615793702102c:2840(env: Windows,mp,1.06.2301160; lib: 2.25.3)
报错代码所在行就是这里
<view class="flex flex-direction-row justify-center align-center">
<button class="down_button" type="primary" @click="downLoadFile(data.down_url.url)">下载</button>
</view>
2***@qq.com (作者)
是data报undefined,data打印出来里面是有down_url字段的,只是组件内没有取到
2023-03-31 21:06
2***@qq.com (作者)
查询了论坛中相关类似的帖子,好像是只要unicloud-db组件中 :getone="true",就会出现这样的情况
2023-03-31 21:08