vue进行web端的开发,如何上传本地图片到leancloud?
-
创建时间
21年3月12日
-
最后回复
21年3月15日
-
1
回复
-
1.0K
浏览
-
2
用户
-
2
链接
vue进行web端的开发,如何上传本地图片到leancloud?
您好,请查阅以下两篇文档:
我也写了一个 Demo 供您参考:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue upload demo</title>
</head>
<body>
<div id="app">
<div>
<input type="file" @change="handleChangeFile" />
<button @click="handleUpload" :disabled="uploading">Upload</button>
</div>
<ul>
<li v-for="url in urls" :key="url">
<a :href="url" target="_blank">{{ url }}</a>
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>
<script src="https://cdn.jsdelivr.net/npm/leancloud-storage@4.10.0/dist/av-min.js"></script>
<script>
AV.init({
appId: 'please-replace-with-your-appId',
appKey: 'please-replace-with-your-appKey',
serverURL: 'https://please-replace-with-your-customized.domain.com',
});
new Vue({
el: '#app',
data: {
file: null,
urls: [],
uploading: false,
},
methods: {
handleChangeFile(e) {
if (e.target.files.length) {
this.file = e.target.files[0]
}
},
handleUpload() {
if (!this.file) {
return
}
this.uploading = true
new AV.File(this.file.name, this.file)
.save()
.then((file) => this.urls.push(file.url()))
.catch(console.error)
.finally(() => this.uploading = false);
},
},
});
</script>
</body>
</html>
主题 | 分类 | 回复 | 浏览 | 活动 |
---|---|---|---|---|
Javascript上传文件时如何限制类型 | SDK / API | 1 | 767 | 16-11-30 |
邮箱验证的token可以自己定制吗, 如果不能, 怎么去识别到底是那个用户的验证 | SDK / API | 0 | 836 | 15-12-29 |
unity排行榜功能如何实现 | SDK / API | 17 | 5.7K | 19-05-21 |
关于Valine评论限制长度的问题 | SDK / API | 1 | 1.0K | 19-03-4 |
每个手机的短信验证码最大条数可以改大一些么? | SDK / API | 2 | 895 | 15-10-26 |