复制代码<template>
</template>
<script>
export default {
methods: {
chooseAndUpload() {
this.chooseFile(() => {
})
},
chooseFile(cb) {
// #ifdef APP-VUE || H5
this.file.choose((files) => {
cb && cb(files)
})
// #endif
// #ifdef MP-WEIXIN
this.chooseFromWX((res) => {
console.log(res);
cb && cb(res)
})
// #endif
},
chooseFromWX(cb) {
wx.chooseMessageFile({
count: 9,
type: 'file',
success(res) {
cb && cb(res);
}
})
}
},
}
</script>
<script module="file" lang="renderjs">
let inputEl = {
el: null,
inject(cb) {
if (!this.el) {
let input = document.createElement("input")
input.type = "file"
input.id = "_file"
input.style.display = "none"
input.addEventListener("change", cb)
this.el = input
document.body.append(input)
}
this.el.click()
return this.el
},
remove(cb) {
if (this.el) {
this.el.removeEventListener("change", cb)
this.el.remove()
this.el = null
}
}
}
export default {
methods: {
_success() {},
choose(cb) {
inputEl.inject(this.fileChange)
cb && (this._success = cb)
},
fileChange(e) {
this._success && this._success(e.target.files)
inputEl.remove(this.fileChange)
}
}
}
</script>
<style>
</style>
提供一种思路,进测试能够再我的安卓机上选择文件,别的还需要完善,各位有指教的话请发表一下自己的思路
2 个评论
要回复文章请先登录或注册
2***@qq.com
aak12345