Vue variable assignment

there is a problem with variable assignment when building a project using vue-cli.
pass in a variable from outside component to render the menu. This variable gets
from $.post, but using different assignment methods will make the result different:
clipboard.png
12
chromeconsole:
clipboard.png

The simple v-for is used in

component. Use props to pass in this variable

question 1: what is the essential difference between these two approaches?
question 2: when declaring a name in data, if you declare mainMenu:" instead of mainMenu: [] in the figure, method 1 will report an error directly. What is the principle of this?

Mar.12,2021

  1. the data object of the Vue instance. Vue will recursively convert the properties of data to getter/setter, so that the properties of data can respond to data changes.

    that is, mainMenu get () , mainMenu set () , if you don't define it, there is no way to trigger the attributes of mainMenu or even on the prototype chain. Of course, you can use Vue.set .

  2. '[I] can you not report an error?

shouldn't you use this.mainMenu.push (this.menu [I]) ?


question 2 is because you use vMurfor, so it is obviously not feasible for you to use v-for to traverse a string. It must be an array type to compile and pass.
question 1 is because you updated the contents of the array
ide/list.html-sharp%E5%8F%98%E5%BC%82%E6%96%B9%E6%B3%95" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.
document indicates that
"
Vue contains a set of ways to observe the variation of the array. So they will also trigger view updates. These methods are as follows:

push ()
pop ()
shift ()
unshift ()
splice ()
sort ()
reverse ()
you open the console and use the items array in the previous example to call the mutation method: example1.items.push ({message: 'Baz'}).

due to the limitation of JavaScript, Vue cannot detect arrays of the following changes:

when you directly set an item using the index, for example: vm.items [indexOfItem] = newValue
when you modify the length of the array, for example: vm.items.length = newLength
"
the way you update is just the case where the change cannot be detected. If vue cannot detect the change of the array, it will not trigger the view update, so the view will not be re-rendered, so this is a feature of vue and has nothing to do with array assignment. Of course, the two arrays are also different. After all, they are references to the two addresses of the two arrays

.

does the first method print out the same mainMenu as the second? ''is an empty string

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