私はSimonのゲームに似たいくつかのコードを持っています。矢印のボタンを使用すると、@mousedownイベントを使用してすべてが完全に機能しました。私はフォントの素晴らしいアイコンでそれをほんの少し上にしたいと思ったが、外観を同じに保ち、<button>
<icon>
のために<button>
をスワップすると、@mousedownイベントは発砲を停止した。他のすべては同じように動作するようです。私のテンプレートからVueフォント - すばらしいアイコンもバインド
:toneButtonPushedもここにある
<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>
:
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()
}
},
私はそれはコンポーネントがインポートされているどのように私はimport文を含めてるとしなければならないいくつかの漠然とした感覚を持っています同じように。より多くのコードが必要な場合は、完全なプロジェクトがここにあります。標準イベントはカスタムコンポーネントでは動作しませんので、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
},
は御馳走を働い、ありがとうございました。 – Aaron