What is the difference between new Vue ({}) and var app=new Vue ({}) in creating vue instances?

    <div id="app">
        

{{msg}}

</div> <script> var app = new Vue({ el: "-sharpapp", data: { msg: "Hello Vue" } }) app.msg=123 console.log(app.msg) console.log(app.$data.msg === app.msg) </script>

when the above code is created by var, the two print messages execute normally, and when created by new Vue, the second print message reports an error. What is the difference between the two methods?


is just new Vue ({}) instead of var app=new Vue ({}) assigned to the variable app , app is not actually an instance of Vue.
it is not actually created until app.msg=123 and does not have $data attribute


you might as well print app <

.
if the id of the dom element does not have the same name as the js built-in object, or is not overridden, then the "variable" of this id points to the dom element. That is, if app is not reassigned, app points to the dom element. Because the second method reassigns app , app points to the Vue object.
in addition, has a similar effect


el: "- sharpapp" means mounting to an element where id is app. Var app is an instance of app vue that is created. Try changing the two names differently

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-1e655f9-5a0ac.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-1e655f9-5a0ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?