N
N
Nikita Kotenko2018-04-22 14:45:56
Vue.js
Nikita Kotenko, 2018-04-22 14:45:56

vue. Weird behavior when passing props to a component. Why error?

I pass the parameters to the child component, which also came to this component through Props (the connectors object is in Props ):

<template>
  <div>
    <connector :index="'amazon'" :url="connectors['amazon']"></connector>
  </div>
</template>

Console writes:
Error in render: "TypeError: Cannot read property 'amazon' of undefined"
TypeError: Cannot read property 'amazon' of undefined

But in fact, everything came to the child component:
5adc75bf16dcb314166888.png
Why does the console swear?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Polos, 2018-04-22
@dimovich85

Do you have an amazon variable or function in data or computed that returns something?
You pass a variable called amazon to props, if you remove v-bind from index, then amazon will become a string and will be passed inside the component.

E
Evgeny Kulakov, 2018-04-23
@kulakoff Vue.js

Before getting a value from an object property, you can check the object itself for existence::url="connectors && connectors['amazon']"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question