【发布时间】:2017-03-25 19:21:41
【问题描述】:
我有一些类似于西蒙游戏的代码。当使用箭头按钮时,使用@mousedown 事件一切正常。我想用令人敬畏的字体图标对其进行一些修饰,但保持外观不变,一旦我将<button> 换成<icon>,@mousedown 事件就会停止触发。其他一切似乎都一样。
来自我的模板:
<div id="top-row">
<icon name="arrow-left" class="but-0" v-bind:class="{ active: pushed0 }" aria-hidden="true" @mousedown="toneButtonPushed(0)"></icon>
<icon name="arrow-left" class="but-1" v-bind:class="{ active: pushed1 }" aria-hidden="true" @mousedown="toneButtonPushed(1)"></icon>
</div>
toneButtonPushed 甚至在这里:
methods: {
toneButtonPushed: function (buttonPushed) {
console.log('hit')
if (this.compTurn === false) {
if (buttonPushed === this.compTones[this.playerTone]) {
const toneName = 'simonSound' + buttonPushed.toString()
this.$refs[toneName].play()
if (this.playerTone === this.compTones.length - 1) {
if (this.compTones.length === this.winLevel) {
this.msg = 'YOU WIN!!!!'
setTimeout(() => {
this.initGame()
}, 2500)
} else this.toggleTurn()
} else {
this.playerTone++
}
} else {
if (this.strict === true) {
this.$refs.wrong.play()
this.initGame()
} else {
this.$refs.wrong.play()
this.compTurn = true
this.showTones()
}
}
} else {
this.$refs.wrong.play()
}
},
我有一种模糊的感觉,它与组件的导入方式有关,所以我也包括了导入语句。如果您需要更多代码,完整的项目在这里。 https://github.com/CliffSmith25/simon
import Icon from 'vue-awesome/components/Icon.vue'
export default {
name: 'app',
data: function () {
return {
compTones: [],
playerTone: 0,
compTurn: true,
intervalID: '',
strict: false,
winLevel: 20,
pushed0: false,
pushed1: false,
pushed2: false,
pushed3: false,
msg: ''
}
},
components: {
Icon
},
【问题讨论】:
标签: vue.js