// pages/add/add.js const db = wx.cloud.database() Page({ /** * 页面的初始数据 */ data: { tempImgList:[], cloudDetailImage:[] }, onLoad: function (options) { }, onShow: function () { this.getTypeGoodsList() }, getTypeGoodsList(){ db.collection('good_Type').get() .then(res=>{ console.log("查找分类目录成功",res) let List = res.data let typeList=[] for(let i =1;i<List.length;i++){ typeList.push(List[i]) } this.setData({ typeList:typeList }) }) .catch(res=>{ console.log("查找分类目录失败",res) }) }, getType(event){ console.log(event) this.setData({ currentIndex:event.currentTarget.dataset.index, type_nameCN:this.data.typeList[event.currentTarget.dataset.index].type_nameCN }) }, chooseDetailImage(){ var that = this; wx.chooseMedia({ count: 9, mediaType: ['image','video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', success(res) { console.log(res.tempFiles.tempFilePath) console.log(res.tempFiles.size) //上传图片 that.uploadImageDetail() } }) }, uploadImageDetail(){ var that = this; for(let l in this.data.tempImgList){ wx.cloud.uploadFile({ cloudPath: 'goodImage/${Math.random()}_${Date.now()}.${this.data.tempImgList[l].match(/\.(\w+)$/)[l]}', filePath: this.data.tempImgList[l], success(res){ console.log(res.fileID) that.data.cloudDetailImage.push(res.fileID) that.setData({ cloudDetailImage:that.data.cloudDetailImage }) } }) } } }) 上传图片没反应
时间: 2023-06-26 07:05:21 浏览: 53
可能是因为上传图片的函数`uploadImageDetail()`没有被调用。你可以在`chooseDetailImage()`中调用`uploadImageDetail()`函数,例如这样:
```
chooseDetailImage(){
var that = this;
wx.chooseMedia({
count: 9,
mediaType: ['image','video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success(res) {
console.log(res.tempFiles.tempFilePath)
console.log(res.tempFiles.size)
that.setData({
tempImgList:res.tempFilePaths
})
//上传图片
that.uploadImageDetail()
}
})
},
```
在`chooseDetailImage()`函数中,首先将选择的图片路径存储到`tempImgList`中,然后再调用`uploadImageDetail()`函数进行图片上传。
相关问题
/src/views/**/*.vue 怎么获取
如果你想获取 Vue 应用程序中 `src/views` 目录下的所有 `.vue` 文件的路径,可以使用 Node.js 的 `glob` 模块来实现。
首先,你需要在你的 Vue 项目中安装 `glob` 模块:
```bash
npm install glob --save-dev
```
然后,在你的代码中,使用以下代码获取匹配的文件路径:
```javascript
const glob = require('glob')
const vueFiles = glob.sync('./src/views/**/*.vue')
console.log(vueFiles)
// Output: [ './src/views/Home.vue', './src/views/About.vue', ... ]
```
这个方法使用了 `glob.sync()` 方法来同步获取所有匹配的文件路径。`./src/views/**/*.vue` 是一个通配符模式,它将匹配 `src/views` 目录下的所有子目录中的 `.vue` 文件。
请注意,在使用这种方法时,你需要确保目标目录中只包含你想要匹配的文件。如果目录中包含其他类型的文件,你可能需要使用其他的通配符模式来排除这些文件。
如何在页面的onload方法中添加代码const db = wx.cloud.database()
对不起,看起来你似乎是在问微信小程序的相关问题。我是一个基于自然语言处理技术的语言模型AI,无法在程序代码中直接进行操作和运行。但是,我可以告诉你如何在页面的onload方法中添加代码。在页面的onload方法中添加代码的步骤如下:
1. 打开小程序开发工具,找到对应的页面文件。
2. 在页面文件中找到onload方法。
3. 在onload方法中添加代码const db = wx.cloud.database()。
注意:为了能够成功执行该代码,你需要先进行微信小程序云开发的相关配置和初始化操作。