avatar.vue
813 Bytes
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
<template>
<img :src="json.path" :alt="json.realName" @error="replaceDefaultUrl">
</template>
<script>
module.exports = {
props: {
jsonStr: {
type: String,
require: true
},
defaultJsonF:{
type:String
}
},
computed: {
json: function () {
return this.jsonStr ? JSON.parse(this.jsonStr) : this.defaultJson;
}
},
methods: {
replaceDefaultUrl: function () {
this.json = {
path: this.defaultJson.path,
realName: this.defaultJson.realName
};
}
},
data: function () {
return {
defaultJson: {
path: '/assets/user-default.png',
realName: '默认头像',
saveName: ''
}
};
},
watch:{
'defaultJsonF':function(){
console.log(this.defaultJsonF);
}
}
};
</script>