首页 > 解决方案 > Vue.js 道具未定义

问题描述

执行此代码时,将输出“未定义”。


子组件

export default {
  porps: [
    'idx'
  ],
  mounted () {
      console.log(this.idx)
  },
} //BambooPage.vue

父组件

<template>
  <div class="bamboo">
    <bamboo-page v-bind:idx="index" v-if="show"></bamboo-page>
  </div>
</template>

<script>
import BambooPage from '@/components/Bamboo/Page/BambooPage.vue'
export default {
  name: 'bamboo',
  data: () => {
    return {
      show: false,
      index: 0
    }
  },
  components: {
    BambooPage
  },
  mounted () {
      this.index = 5
      this.show = true
  },
}
</script>

在 Vue Devtools 上,子组件中有 $attars "idx: 5"。
我能怎么做?

标签: vue.jsvue-componentvue-props

解决方案


你在 word 道具中有错字) porps: [ 'idx' ]

换成道具


推荐阅读