0

I have a component with empty data array

data: () => ({
    selectedResource : [],
}),

but when i try to add some item to this array i got an error

    selectResource(resource){
        console.log(this.selectedResource);
        this.selectedResource.append(resource)
    }

this.selectedResource.append is not a function

5
  • 5
    append() is a jquery function, use push() instead
    – niclas_4
    Nov 1, 2018 at 7:50
  • this.selectedResource.push is not a function
    – Viktor
    Nov 1, 2018 at 9:27
  • where do you use the method? could you show the surrounded code please
    – niclas_4
    Nov 1, 2018 at 9:29
  • there is a lot of code and i can just upload file to free file-service. file.sampo.ru/nnrknd
    – Viktor
    Nov 1, 2018 at 9:35
  • Wont download it here at work sorry, I´ll look into it when home
    – niclas_4
    Nov 1, 2018 at 9:40

2 Answers 2

0

Using this should work

    data() {
        return {
            selectedResource: [],
        }
    },
0

You can use $set for add item to array:

this.$set(yourArray, 'yourIndex', 'YourValue')

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.