iview/examples/routers/avatar.vue

27 lines
828 B
Vue
Raw Normal View History

2017-08-15 10:07:15 +08:00
<template>
2018-02-26 10:15:56 +08:00
<div class="demo-avatar">
<Avatar :style="{background: color}">{{ user }}</Avatar>
<Button size="small" @click="handleChange">Change</Button>
2017-08-15 11:03:20 +08:00
</div>
2017-08-15 10:07:15 +08:00
</template>
<script>
2018-02-26 10:15:56 +08:00
const UserList = ['二', '小二', '三', '二个人'];
const ColorList = ['#f56a00', '#7265e6', '#ffbf00', '#00a2ae'];
2017-08-15 10:07:15 +08:00
export default {
2017-08-15 14:52:56 +08:00
data () {
return {
2018-02-26 10:15:56 +08:00
user: UserList[0],
color: ColorList[0]
2017-08-15 14:52:56 +08:00
}
},
methods: {
2018-02-26 10:15:56 +08:00
handleChange () {
const index = UserList.indexOf(this.user);
this.user = index < UserList.length - 1 ? UserList[index + 1] : UserList[0];
this.color = index < ColorList.length - 1 ? ColorList[index + 1] : ColorList[0];
2017-08-15 14:52:56 +08:00
}
}
2017-08-15 10:07:15 +08:00
}
</script>