File tree Expand file tree Collapse file tree 2 files changed +51
-27
lines changed Expand file tree Collapse file tree 2 files changed +51
-27
lines changed Original file line number Diff line number Diff line change 1- // import fetch, { tpFetch } from 'utils/fetch';
1+ import fetch from 'utils/fetch' ;
22
3- // export function getToken() {
4- // return fetch({
5- // url: '/qiniu/upload/token',
6- // method: 'get'
7- // });
8- // }
9- // export function upload(data) {
10- // return tpFetch({
11- // url: 'https://upload.qbox.me',
12- // method: 'post',
13- // data
14- // });
15- // }
16-
17-
18- // /* 外部uri转七牛uri*/
19- // export function netUpload(token, net_url) {
20- // const imgData = {
21- // net_url
22- // };
23- // return fetch({
24- // url: '/qiniu/upload/net/async',
25- // method: 'post',
26- // data: imgData
27- // });
28- // }
3+ export function getToken ( ) {
4+ return fetch ( {
5+ url : '/qiniu/upload/token' , // 假地址 自行替换
6+ method : 'get'
7+ } ) ;
8+ }
Original file line number Diff line number Diff line change 1+ <template >
2+ <el-upload
3+ action =" https://upload.qbox.me"
4+ :data =" dataObj"
5+ drag
6+ :multiple =" true"
7+ :before-upload =" beforeUpload" >
8+ <i class =" el-icon-upload" ></i >
9+ <div class =" el-upload__text" >将文件拖到此处,或<em >点击上传</em ></div >
10+ </el-upload >
11+ </template >
12+
13+
14+ <script >
15+ import { getToken } from ' api/qiniu' ; // 获取七牛token 后端通过Access Key,Secret Key,bucket等生成token
16+ // 七牛官方sdk https://developer.qiniu.com/sdk#official-sdk
17+
18+ export default {
19+ data () {
20+ return {
21+ dataObj: { token: ' ' , key: ' ' },
22+ image_uri: [],
23+ fileList: []
24+ }
25+ },
26+ methods: {
27+ beforeUpload () {
28+ const _self = this ;
29+ return new Promise ((resolve , reject ) => {
30+ getToken ().then (response => {
31+ const key = response .data .qiniu_key ;
32+ const token = response .data .qiniu_token ;
33+ _self ._data .dataObj .token = token;
34+ _self ._data .dataObj .key = key;
35+ resolve (true );
36+ }).catch (err => {
37+ console .log (err)
38+ reject (false )
39+ });
40+ });
41+ }
42+ }
43+ }
44+ </script >
You can’t perform that action at this time.
0 commit comments