changeziliao.vue
2.5 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<template>
<div class="containerbox">
<div class="changeitem flextwo">
<div class="changeitemleft">头像</div>
<div class="changeitemright flexone">
<!-- <img :src="avatar" alt class="headimg" /> -->
<van-uploader
v-model="fileList"
multiple="false"
:after-read="afterRead"
:max-count="1"
/>
<img src="../../../assets/grayrow.png" alt class="yourow" />
</div>
</div>
<div class="changeitem flextwo">
<div class="changeitemleft">姓名</div>
<div class="changeitemleft">
<input type="text" v-model="username" placeholder="请输入姓名" />
</div>
</div>
<div class="kaishilu" @click="save">保存</div>
</div>
</template>
<script>
import Vue from 'vue';
import { Toast, Uploader } from "vant";
import "vant/lib/index.css";
Vue.use(Toast);
Vue.use(Uploader);
export default {
data() {
return {
username: "",
avatar: "",
fileList:[],
chuanimage:''
};
},
created() {
this.username = this.$route.query.username;
this.avatar = this.$route.query.avatar;
console.log(this.avatar)
let obj={
url:this.avatar
}
this.fileList.push(obj)
},
methods: {
// 上传图片
afterRead(file) {
let that = this;
console.log(file);
console.log(file.length);
var formdata = new FormData();
formdata.append("file", file.file);
var url = "/api/common/upload";
let param = {
id: 1
};
that.$uploadFile
.post(url, formdata)
.then(function(res) {
console.log(res);
that.cardzheng = false;
let url = "http://tangyuanji.t.brotop.cn" + res.data.url;
that.avatar=url
that.chuanimage=res.data.url
})
.catch(err => {
console.log(err);
});
},
save() {
let that = this;
var url = "/api/user/profile";
let param = {
avatar: that.chuanimage,
nickname: that.username
};
console.log(param)
that.$axios
.post(url, param)
.then(function(res) {
console.log(res);
Toast("保存成功");
that.$router.go(-1);
})
.catch(function(err) {
console.log(err);
});
}
}
};
</script>
<style scoped>
@import "../../../style/usercenter.css";
.changeitemleft input {
text-align: right;
}
</style>