npm install ali-ossjavascript
getClient() { let OSS = require('ali-oss') this.client = new OSS({ //服務器地區 region: 'oss-cn-beijing', //Accesstoken中的keyid accessKeyId: 'LTAI4FhbwaMVJFsRBDFqqaB6', //Accesstoken中的KeySecret accessKeySecret: 'haBJpDQYdrUjqkZkUnXNEZT20fvdz9', //bucket實例名稱 bucket: 'johnnycc', }) }
handleFile() { //獲取oss對象、client實例 this.getClient() //取得用戶選擇的文件 this.file = this.$refs.upload.files[0] var _this = this async function put() { try { let result = await _this.client.put( //傳入文件名 _this.$refs.upload.files[0].name, //傳入文件 _this.file ) //得到結果中返回的url _this.avatar = result.url _this.changeMessage() } catch (e) { console.log(e) } } put() }
更多內容請你們關注Johnny博客前端