1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以使用palindrome()
類(lèi)中的函數(shù):
創(chuàng)建一個(gè)數(shù)據(jù)道具來(lái)保存用戶輸入(例如, named?
input
),并綁定<v-text-field>
?v-model
到它。使用您在問(wèn)題中提到的函數(shù),創(chuàng)建一個(gè)返回是否為回文的計(jì)算道具(例如, named )。
isPalindrome
input
使用樣式綁定應(yīng)用
color
基于isPalindrome
.使用字符串插值來(lái)顯示用戶輸入是否為回文,基于
isPalindrome
.
<template>
? <v-row>
? ? <v-text-field label="Palindrome" v-model="input" 1?? />
? ? <span :style="{ color: isPalindrome ? 'green' : 'red' }" 3??>
? ? ? {{ isPalindrome ? 'Yes' : 'No' }} 4??
? ? </span>
? </v-row>
</template>
<script>
import { Component, Vue } from 'vue-property-decorator'
function palindrome(str: String) { /*...*/ }
@Component
export default class Palindrome extends Vue {
? input = '' // 1??
? get isPalindrome() { // 2??
? ? return this.input && palindrome(this.input)
? }
}
</script>
添加回答
舉報(bào)