avatar.js
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import userApi from '@/api/user'
import {Button, Cell, CellGroup, Field, Image, NavBar, Toast, Uploader} from 'vant'
import store from '@/store'
import storage from '@/utils/storage'
const baseApi = process.env.VUE_APP_BASE_API
export default {
components: {
[Button.name]: Button,
[Cell.name]: Cell,
[CellGroup.name]: CellGroup,
[NavBar.name]: NavBar,
[Field.name]: Field,
[Toast.name]: Toast,
[Image.name]: Image,
[Uploader.name]: Uploader
},
data() {
return {
avatarUrl: 'http://microapp.gitee.io/linjiashop/logo.jpg'
}
},
mounted() {
this.init()
},
methods: {
init() {
this.user = storage.getUser()// store.state.app.user
if (this.user.avatar) {
this.avatarUrl = baseApi + '/file/getImgStream?idFile=' + this.user.avatar
}
},
onClickLeft() {
this.$router.go(-1)
},
afterRead(vantFile) {
userApi.upload({
name: vantFile.file.name,
type: vantFile.file.type,
base64: vantFile.content
}).then(response => {
//更新用户信息
store.dispatch('app/toggleUser', response.data)
this.avatarUrl = baseApi + '/file/getImgStream?idFile=' + response.data.avatar
})
}
}
}