Vue.component("roll-amplify-img", { template: ` `, props: { list:{ type:Array }, url:{ type:String }, show:{ type:Boolean } }, data() { return { index: -1, imgUrl:'', imgShow:false } }, created() { }, mounted(){ }, methods: { init(){ this.imgUrl = this.url this.imgShow = this.show this.towards() }, towards(){ for (let i = 0; i < this.list.length ; i++) { if(this.list[i] == this.imgUrl){ this.index = i break } } }, onTowardsLeft(){ this.index = this.index - 1 if(this.index < 0){ this.imgUrl = this.list[this.list.length-1] this.index = this.list.length-1 }else{ this.imgUrl = this.list[this.index] } }, onTowardsRight(){ this.index = this.index + 1 if(this.index > this.list.length-1){ this.imgUrl = this.list[0] this.index = 0 }else{ this.imgUrl = this.list[this.index] } }, onCloseBtn(){ this.imgShow = false this.$emit("show",false) }, }, watch:{ list:function (o,n) { this.init() }, url:function (o,n) { this.init() }, show:function (o,n) { this.init() } }, })