4

My code:

interface Item {
  title: string;
  type: string;
  description: string;
}

data() {
  return {
    id: "",
    item: {} as Item,
    file: //Here
  };
}

Hello, I'm looking to add a File type to my vuejs data.

I saw this solution that could work:

interface Item {
  title: string;
  type: string;
  description: string;
  file: File;
}

data() {
  return {
    id: "",
    item: {} as Item
  };
}

but I don't want to add my data file to my Item interface or in an object.

1 Answer 1

1

You can write an interface (or a type) to data itself and just add the file property to it.

interface Item {
  title: string;
  type: string;
  description: string;
}

interface State {
  id: string;
  item: Item;
  file: null | File;
}

data(): State {
  return {
    id: '',
    item: {
      title: '',
      type: '',
      description: '',
    },
    file: null,
  };
},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.