Now the popular data is separated from the view, just like the text attribute of the control in the layout file in Android development, it is not recommended to use hard-coded data, but to use strings.xmlthe string variable defined in the string resource file.
1. To propose tasks
Write the code to display the following table
2. Complete the task
To display a table on the web page, the data can be written in the table cell, or the table can be separated from the data, and the data can be set by script.
Using DOM and jQuery to set data for the table is essentially the same. It gets each page element, and then sets the attribute value for each element. The data is scattered and not packaged into a data collection, such as json, while Vue The way to use it is to package the way to provide data.
(3) Use Vue to set data for the table
create test03.htmlfile
Vue constants Studentprovide a data() function that returns JSON data - a packaged set of key-value pair data
Vue creates a Vue instance or application based on constants Student, calls the mount() function, binds the page element, and then {
{key}}the JSON data returned by the data() function can be obtained in the page element.
<!DOCTYPEhtml><html><head><title>test03</title><scriptsrc="https://unpkg.com/vue@next"></script></head><body><divid='student'><tableborder='1'cellpadding='5'><tr><td>学号</td><td>{
{ id }}</td></tr><tr><td>姓名</td><td>{
{ name }}</td></tr><tr><td>性别</td><td>{
{ gender }}</td></tr><tr><td>年龄</td><td>{
{ age }}</td></tr><tr><td>专业</td><td>{
{ major }}</td></tr><tr><td>电话</td><td>{
{ telephone }}</td></tr></table></div><script>const Student ={
data(){
return{
id:20220101,
name:'萌萌哒',
gender:'男',
age:20,
major:'大数据技术',
telephone:'13934345678'}}}
Vue.createApp(Student).mount('#student')</script></body></html>