【问题标题】:Property or method (...) is not defined on the instance but referenced during render属性或方法 (...) 未在实例上定义,但在渲染期间被引用
【发布时间】:2018-09-17 05:53:41
【问题描述】:

"属性或方法 "show" 未在实例上定义,但 在渲染期间引用。确保此属性是反应性的, 无论是在数据选项中,还是对于基于类的组件,通过 初始化属性”

这是我的代码。

<script>
import { SlideYUpTransition } from 'vue2-transitions'

export default {
  data: () => ({
    listitems: [{
        title: '출결관리',
        path: '/attendanceCheck'
      },
      {
        title: '학생관리',
        path: '/studentAdministration'
      },
      {
        title: '알림설정',
        path: '/notificationSetting'
      }
    ],
    components: {
      SlideYUpTransition
    },
    data() {
      return {
        show: true
      }
    }
  })
}
</script>
<style>

/*-- Contents --*/
/* .content {
  width: 580px;
  padding: 20px;
  margin-bottom: 20px;
  float: left;
} */


@media ( max-width: 480px) {
  .container {
    width: auto;
  }
  .content {
    float: none;
    width: auto;
  }
}
</style>
<template>

  <!-- Contents ( Image, Notice ) -->
  <div class = "contents">
    <section>
        <v-parallax src="/images/bg.png" height="650"></v-parallax>
    </section>
    <slide-y-up-transition  >
      <div v-show="show">Your content here</div>
    </slide-y-up-transition>
  </div>
</template>

【问题讨论】:

  • 在你发布的第一个脚本中,在 export default 里面,我看到两个数据函数,我认为你应该只使用一个数据函数并将所有反应数据放在那里

标签: javascript laravel vue.js vue-component


【解决方案1】:

此错误的主要原因是您可能在“template”标签内使用了“model”,但忘记在“script”标签内的“数据”部分声明。

例如:

<template>
    <el-form ref="form" :model="form" label-width="120px"> ##<=== form model used here
        <el-form-item label="Name">
            <el-input v-model="form.name"></el-input>
        </el-form-item>
  </el-form>
 </template>

但在您的“Script”标签中,您可能没有使用过它

export default {

  data: () => ({

      form:{
          name: ''   <----- Declare andd initialize here
          }

  }),


  methods:{

  },

  components: {

  }
};

这会解决你的问题....

【讨论】:

    【解决方案2】:

    组件的结构应该有data 和components 作为顶级属性:

    export default {
      data: () => ({
        listitems: [
          {
            title: '출결관리',
            path: '/attendanceCheck'
          },
          {
            title: '학생관리',
            path: '/studentAdministration'
          },
          {
            title: '알림설정',
            path: '/notificationSetting'
          }
        ],
        show: true
      }),
      components: {
        SlideYUpTransition
      }
    }
    

    data是一个返回组件状态的函数,components是一个对象。

    【讨论】:

    • 不要认为你应该使用粗箭头来表示数据
    • 当然,它不必要地绑定this,但它会破坏什么吗?
    • 我认为它会,但它没有,dw!
    猜你喜欢
    • 2022-07-14
    • 2020-03-06
    • 2021-07-07
    • 2018-05-07
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 2018-06-22
    相关资源
    最近更新 更多