Vue-cli data data rendering

export default {
    name: "HelloWorld",
    data () {
        return {}
    }
}    

text();

function text(){
    //datamsg
}
May.22,2021

as far as I know, it is not allowed.

because your export default is just a class, not an instantiated VM.
unless this is an instantiated vm, you can. Since your component is not a top-level element, it is recommended to manage it in vuex.

if you are sure you want to do it this way, my advice is this:

// sub-app.js
export default new Vue({
    el: '-sharpsub-app' 
    name: 'HelloWorld',
    data () {
        return {}
    }
})    

// 
import SubApp from '../subApp.vue'
text();

function text(){
    SubApp.$data.msg = 'new msg'
}

what is the scenario of such a requirement?
generally uses data in data in templates.

<template>
    <div>
    {{msg}}
    </div>
</template>

clipboard.png


this event is either the method defined in methods, where you can also operate this.a to access the assignment directly

var vm = new Vue({
  data: { a: 1 },
  methods: {
    plus: function () {
      this.aPP
    }
  }
})
vm.plus()

or the official website: vm.$data

var vm = new Vue({
  data: data
})


vm.a // => 1
vm.$data === data
Menu