Wpis z mikrobloga

Mam problem związany z #vue #vuejs. Generalnie rzuca mi błędem w metodzie gdy wykorzystuję klucz z data(), który jako wartość ma podane this.placeholder. Chciałbym otypować data ale nie mam pojęcia jak się za to zabrać. Wczoraj zacząłem przygodę z vue.

export default defineComponent({
name: "CustomDropDown",
props: {
label: {
type: String,
default: "Character",
},
placeholder: {
type: String,
default: "Pick a character",
},
options: {
type: Array,
default() {
return [
{ value: "Rick Sanchez" },
{ value: "Morty Smith" },
{ value: "Summer Smith" },
{ value: "Birdperson" },
];
},
},
},
data() {
return {
selected: this.placeholder,
showDropDown: false,
};
},
methods: {
onClick(value: string) {
this.selected = value;
this.showDropDown = !this.showDropDown;
},
},
});

Błąd rzuca w this.selected, którego treść to:

(property) selected: Function | ((Prop | null | undefined) & Function)
Type 'string' is not assignable to type 'Function | ((Prop | null | undefined) & Function)'.Vetur(2322)

#vue
  • 2