Skip to content

When i use setup function in vue2 project i get some error in console #693

@BABA983

Description

@BABA983
<script lang="ts">
import {
  defineComponent,
  ref,
  reactive,
  computed,
  onActivated,
  getCurrentInstance,
  ComponentInternalInstance,
  onBeforeMount,
  onMounted,
  SetupContext
} from '@vue/composition-api';
import DownloadDialog from '@/components/dialog/downloadDialog.vue';
import EmptyList from '@/components/emptyList/index.vue';
import Pagination from '@/components/Pagination/index.vue';
import ProtocolViewer from '@/components/protocolViewer/index.vue';
import * as dateUtil from '@/utils/dateUtil';
import { isPositiveNum } from '@/utils/formValidate';
import { clearObjectValue } from '@/utils/utils';
// import { Component, Ref, Vue } from 'vue-property-decorator';
import agreementMixin from '../composables/agreement.js';

interface IBillStatusItem {
  name: string;
  value: string;
}

export default defineComponent({
  components: { EmptyList, ProtocolViewer, DownloadDialog, Pagination },
  data() {
    return {};
  },
  setup(props: any, context: SetupContext) {
    let hasData = ref(false),
      billStatus: Array<IBillStatusItem> = reactive([]),
      form = reactive({
        billCode: '',
        billMaxMoney: '',
        billMinMoney: '',
        maturityDate: [],
        outputDate: [],
        inputName: '',
        outputName: '',
        queryType: ''
      }),
      pageSize = ref(10),
      pageNum = ref(1),
      total = ref(0),
      list: any = ref([]),
      blockHeight = ref(0),
      maturityStartDate = computed(() => {
        return form.maturityDate && form.maturityDate[0]
          ? dateUtil.getValueOfDateStart(form.maturityDate[0])
          : '';
      }),
      maturityEndDate = computed(() => {
        return form.maturityDate && form.maturityDate[1]
          ? dateUtil.getValueOfDateEnd(form.maturityDate[1])
          : '';
      }),
      outputStartDate = computed(() => {
        return form.outputDate && form.outputDate[0]
          ? dateUtil.getValueOfDateStart(form.outputDate[0])
          : '';
      }),
      outputEndDate = computed(() => {
        return form.outputDate && form.outputDate[1]
          ? dateUtil.getValueOfDateEnd(form.outputDate[1])
          : '';
      }),
      { proxy } = getCurrentInstance() as ComponentInternalInstance;
    const getList = async () => {
        console.log('getList');
      },
      resetSearch = () => {
        // some logic
      },
      exportExcel = () => {
        // some logic
      };

    onBeforeMount(() => {
      console.log('beforeMount')
    });
    onMounted(() => {
      console.log('mounted!');
    });
    onActivated(async () => {
      getList();
    });

    return {
      hasData,
      billStatus,
      form,
      pageSize,
      pageNum,
      total,
      list,
      blockHeight,
      maturityStartDate,
      proxy,
      ...agreementMixin(),
      getList,
      resetSearch,
      exportExcel
    };
  }
});
</script>

it show this error in console
image

and if my getList,resetSearch,exportExcel these 3 function return at the end.Vue will warn

 return {
      ...
      getList,
      resetSearch,
      exportExcel
    };
  }

image

but if i put them at the beginning like this,it will be fine

      return {
         getList,
         resetSearch,
         exportExcel
         ...
         ...agreementMixin
}

but the [Vue warn]: Error in data(): "TypeError: Cannot use 'in' operator to search for '__ob__' in undefined" error still show up in the console
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds reproductionWe need a runnable reproduction from the OP

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions