Can you new objects in the data of vue

  data: function () {
    class baseObj{
        constructor(src){
            this.flag=true,
            this.mapvLayer=null,
        //   this.data=null,
            this.total=0,
            this.src=require(src)            
        }
    }      
    return {
      //
    //   history:{
    //       flag:true,
    //       mapvLayer:null,
    //       data:null,
    //       total:0,
    //       src:require("../../../../assets/images/map_people.png")
    //   },
      history:new baseObj("../../../../assets/images/map_people.png"),

reported this wrong: Cannot find module "."
is this all right? later, I wrote that class into a js file alone, and it didn"t seem to work to import it. I asked for a great god

.

Yes, the problem lies in your other code, not here. Here is


you can new object
in the data of vue. Your problem here is that the resource of require is a variable this.src=require (src)


require should only be a static path, not a dynamic variable

.
Menu