vue组件重复使用问题_游戏活动中可重复使用的Vue组件

vue组件重复使用问题

视觉游戏 (vue-games)

A npm package which allows you to include components with games in your vue application. For now it only have a hangman game.

一个npm软件包,可让您在vue应用程序中包含游戏组件。 目前,它只有一个子手游戏。

安装 (Installation)

npm install --save vue-games

子手游戏 (Hangman Game)

<template>
  <hangman-game />
</template>

<script>
import 'vue-games'
</script>
物产 (Properties)
PropertyTypeDefault Value
wordsArray['Pear', 'Apple', 'Tomatoe', 'Blackberry', 'Strawberry']
showPlayAgainBooleantrue
winMessageString'You win!'
loseMessageString'You lost!'
属性 类型 默认值
数组 ['Pear', 'Apple', 'Tomatoe', 'Blackberry', 'Strawberry']
showPlayAgain 布尔型 true
winMessage的 'You win!'
lostMessage 'You lost!'

As default, HangmanGame component will have a default array with some words to play. Will show a play again button every time a game is ended, and 'You win!' and 'You lost!' messages. Its posible to change all this default values. Also, every time a game ends this component will emit gameFinishedwith the current word, and a boolean value telling if the playes has won or has lost.

默认情况下,HangmanGame组件将具有带有一些单词的默认数组。 每当游戏结束时,都会显示再次播放按钮,并且“您赢了!” 和“你输了!” 消息。 可以更改所有这些默认值。 此外,每次游戏结束时,此组件都会发出gameFinished并带有当前单词,并提供一个布尔值,该值指示玩法是赢还是输。

用法示例: (Usage example:)

Lets say we are spanish speakers, so we want to change default values:

假设我们说西班牙语,所以我们想更改默认值:

<template>
  <hangman-game
    :words="words"
    :show-play-again="false"
    :winMessage="winMessage"
    :loseMessage="loseMessage"
    @gameFinished="gameFinished"
  />
</template>
<script>
import 'vue-games'
export  default {
  data () {
    return {
      words: ['Pera', 'Manzana', 'Tomate', 'Cereza', 'Frutilla'],
      winMessage:  'Ganaste!',
      loseMessage:  'Perdiste!'
    }
  },

  methods: {
    gameFinished: function (word, lose) {
      console.log('game finished!!!')
      console.log('user was guessing word:', word)
      console.log('she/he/it lost?', lose)
    }
  }
}
</script>

翻译自: https://vuejsexamples.com/reusable-vue-components-with-games-activities/

vue组件重复使用问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值