But sometimes we want to bind value to a dynamic property of the Vue instance. In this case, we can use v-bind to achieve this, and the value of this property does not need to be a string.
Question:
1. Explain the above paragraph in detail
2. Combine the following codes to write a complete demo
Checkbox
// 当选中时 vm.toggle === vm.a // 当没有选中时 vm.toggle === vm.b
single button
// 当选中时 vm.pick === vm.a
Select List Settings
// 当选中时 typeof vm.selected // -> 'object' vm.selected.number // -> 123
It refers to the value of radio, checkbox or select options, which can be a static string or instance attributes such as instance data and calculated attributes.
In fact, the following example has been given in detail:
When the user clicks the radio, vm.picked is the character String "a", and
, when the user selects, vm.pick is the instance attribute of vm.a .
The select list example is also easy to understand.
In fact, if you type the code and run it yourself, you will almost understand it. However, when typing the code, there may be some error messages (if there is no instance data of a, it will prompt that the bound data is not declared. At this time, in the data Just add an a to it). The thing about Vue that is not very friendly to Chinese learners is that the error prompts in its console are all in English. Some children who are afraid of English may be put off.