Vue initialization / reset Datagram error

The
  • form is complex. Use this method to initialize the data when closed:
closeDialog(){
    Object.assign(this.$data, this.$options.data())
    },            
  • but the external js method is introduced in data:
         start_time:this.$dayjs().format("YYYY-MM-DD"),
  • an error will be reported when calling closeDialog:

  • what should I do with it?
May.31,2022

the call to this.$options.data () changes the this in the current data and no longer points to the current Vue instance. There is no $dayjs () method on this this, so an error is reported.
solution:
introduce this method into utils.js

import {getTime} from '@/utils/utils.js'
data () {
    return {
        start_time: getTime()
    }
}
The $dayjs method does not exist on
this , and is not bound to $dayjs . If npm is introduced, just use it directly


both of you upstairs are very clear about the
@ qinchao888 principle, and the solution is right. Awesome!
because I use this function on a lot of pages, it's troublesome to introduce every page I use, so it's better to bind it globally.

so after understanding your answer, I slightly modified my data and related methods

        1.  '' 
        
        data(){
            return{
                start_time: '',
            }
        },
        2. watch,mounted,onShow
        
        watch:{
            propsData(newValue, oldValue) {
                this.start_time = this.$dayjs().valueOf()
            }
        },
        3. :
        resetData() {
                Object.assign(this.$data, this.$options.data())
            },

there are too many forms in the project, which are emptied after each submission. Manual re-assignment is both troublesome and error-prone, and this method of clearing data is very practical;
on the PC side, element-ui form verification is introduced, and calling this method will lead to automatic verification when entering the form, which has not been solved yet.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b360bd-2bffc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b360bd-2bffc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?