上代码
// 下载依赖
npm install ali-oss
// 或者
<script src="http://gosspublic.alicdn.com/aliyun-oss-sdk.min.js"></script>
<input
type="file"
name="picFieldName"
id="picFieldId"
@change="uploadPic($event)"
/>
uploadPic(e) {
console.log(e);
const OSS = require("ali-oss");
var client = new OSS({
region: "",// oss 地域
endpoint: "", //外网域名
accessKeyId: "",
accessKeySecret: "",// 密钥
bucket: "",
});
var file = e.target.files[0];
//采用时间戳重命名
var last=file.name.substr(file.name.lastIndexOf("."),file.name.length)
var fileName=Date.parse(new Date()) + last;
client
.put(fileName, file)
.then((results) => {
console.log(results);
})
.catch((err) => {
console.log(err);
});
},