diff --git a/src/components/index/text.vue b/src/components/index/text.vue index c50ba1024112ce5406db55350709735de750f27f..423b20f663a60cfbcadd1924510df901c594861d 100644 --- a/src/components/index/text.vue +++ b/src/components/index/text.vue @@ -1,6 +1,11 @@ @@ -9,10 +14,25 @@ import CreateText from "@/assets/js/createText"; export default { data() { return { - length: 20, + length: 2, + currentIndex: 0, text: "", }; }, + computed: { + currentLetter() { + return this.$store.state.currentLetter; + }, + }, + watch: { + currentLetter(val) { + if (val === null) return; + const currentLetter = this.text[this.currentIndex]; + if (val.toLowerCase() === currentLetter.toLowerCase()) { + this.next(); + } + }, + }, created() { this.createTextList(); }, @@ -22,8 +42,49 @@ export default { const res = arr.map(() => CreateText.create()); this.text = res.join(" ").toLowerCase(); }, + next() { + this.currentIndex++; + if (this.currentIndex === this.text.length) { + this.currentIndex = 0; + this.createTextList(); + } + }, + }, + filters: { + formatLetter(val) { + if (!val) return ""; + return val === " " ? "␣" : val; + }, }, }; - +