第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Vue 3 和 Typescript - 無法訪問方法中的數(shù)據(jù)屬性

Vue 3 和 Typescript - 無法訪問方法中的數(shù)據(jù)屬性

幕布斯7119047 2023-09-21 16:20:25
我試圖用我正在編寫的方法訪問我的數(shù)據(jù),但它似乎不起作用。我收到 TS2339 Typescript 錯(cuò)誤,指出類型中不存在該屬性。TS2339: Property 'players' does not exist on type '{ onAddPlayers(): void; getPlayerPlaceholder(index: number): string; }'.       47 |   methods: {    48 |     onAddPlayers() {  > 49 |       this.games = prepareGames(this.players as PadelPlayer[]);       |                                      ^^^^^^^    50 |     },    51 |     getPlayerPlaceholder(index: number) {    52 |       const playerNumber = Number(index) + 1;這是該組件的代碼:<script>import { PadelGame } from "@/models/padelGame.interface";import { getPadelPlayers, prepareGames } from "../services/americanoService";import { PadelPlayer } from "@/models/padelPlayer.interface";const padelGames: PadelGame[] = [];export default {  data() {    return {      players: getPadelPlayers(),      games: padelGames,    };  },  methods: {    onAddPlayers() {      this.games = prepareGames(this.players as PadelPlayer[]);    },    getPlayerPlaceholder(index: number) {      const playerNumber = Number(index) + 1;      return "Spelare " + playerNumber;    },  },};</script>
查看完整描述

1 回答

?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

defineComponent要獲得類型推斷,您應(yīng)該使用從 vue 導(dǎo)入來創(chuàng)建組件實(shí)例:


<script>

import { PadelGame } from "@/models/padelGame.interface";

import { getPadelPlayers, prepareGames } from "../services/americanoService";

import { PadelPlayer } from "@/models/padelPlayer.interface";

import {defineComponent} from 'vue'

const padelGames: PadelGame[] = [];


export default defineComponent({

  data() {

    return {

      players: getPadelPlayers(),

      games: padelGames,

    };

  },

  methods: {

    onAddPlayers() {

      this.games = prepareGames(this.players as PadelPlayer[]);

    },

    getPlayerPlaceholder(index: number) {

      const playerNumber = Number(index) + 1;

      return "Spelare " + playerNumber;

    },

  },

});

</script>


查看完整回答
反對 回復(fù) 2023-09-21
  • 1 回答
  • 0 關(guān)注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號