1. Comparison with Vue21. New features of Vue3
2. Comparison of response principles between Vue2 and Vue3 shortcoming:
Solution:
3. Rewrite array methods to detect array changes advantage:
shortcoming:
The above quotes "[Comparison of Vue2 and Vue3]" (https://www.cnblogs.com/yaxinwang/p/13800734.html) 4. Intuitive experienceAt present, Vue2 is still the main one in actual work 2. Data binding example using Vue3In the previous article Vue3 integrated HTTP library axios details, we have realized the return of background data and displayed it on the front page (although it is in the console), but this only means that 90% of it has been completed. The next step is how we return data from the background interface and how to display it on the page. 1. Use ref to implement data binding We still need to modify it in <template> <a-layout> <a-layout-sider width="200" style="background: #fff"> <a-menu mode="inline" v-model:selectedKeys="selectedKeys2" v-model:openKeys="openKeys" :style="{ height: '100%', borderRight: 0 }" > <a-sub-menu key="sub1"> <template #title> <span> <user-outlined /> subnav 1 </span> </template> <a-menu-item key="1">option1</a-menu-item> <a-menu-item key="2">option2</a-menu-item> <a-menu-item key="3">option3</a-menu-item> <a-menu-item key="4">option4</a-menu-item> </a-sub-menu> <a-sub-menu key="sub2"> <template #title> <span> <laptop-outlined /> subnav 2 </span> </template> <a-menu-item key="5">option5</a-menu-item> <a-menu-item key="6">option6</a-menu-item> <a-menu-item key="7">option7</a-menu-item> <a-menu-item key="8">option8</a-menu-item> </a-sub-menu> <a-sub-menu key="sub3"> <template #title> <span> <notification-outlined /> subnav 3 </span> </template> <a-menu-item key="9">option9</a-menu-item> <a-menu-item key="10">option10</a-menu-item> <a-menu-item key="11">option11</a-menu-item> <a-menu-item key="12">option12</a-menu-item> </a-sub-menu> </a-menu> </a-layout-sider> <a-layout-content :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }" > {{ebooks}} <pre> {{ebooks}} </pre> </a-layout-content> </a-layout> </template> <script lang="ts"> import { defineComponent,onMounted,ref } from 'vue'; import axios from 'axios'; export default defineComponent({ name: 'Home', setup(){ console.log('set up'); const ebooks = ref(); onMounted(()=>{ axios.get("http://localhost:8888/ebook/list?name=spring").then(response =>{ console.log("onMounted"); const data=response.data; ebooks.value=data.content; }) }) return { eBooks } } }); </script> Knowledge points:
Recompile, start the service, and see the results as follows: 2. Use reactive to implement data binding Similarly, modify it in <template> <a-layout> <a-layout-sider width="200" style="background: #fff"> <a-menu mode="inline" v-model:selectedKeys="selectedKeys2" v-model:openKeys="openKeys" :style="{ height: '100%', borderRight: 0 }" > <a-sub-menu key="sub1"> <template #title> <span> <user-outlined /> subnav 1 </span> </template> <a-menu-item key="1">option1</a-menu-item> <a-menu-item key="2">option2</a-menu-item> <a-menu-item key="3">option3</a-menu-item> <a-menu-item key="4">option4</a-menu-item> </a-sub-menu> <a-sub-menu key="sub2"> <template #title> <span> <laptop-outlined /> subnav 2 </span> </template> <a-menu-item key="5">option5</a-menu-item> <a-menu-item key="6">option6</a-menu-item> <a-menu-item key="7">option7</a-menu-item> <a-menu-item key="8">option8</a-menu-item> </a-sub-menu> <a-sub-menu key="sub3"> <template #title> <span> <notification-outlined /> subnav 3 </span> </template> <a-menu-item key="9">option9</a-menu-item> <a-menu-item key="10">option10</a-menu-item> <a-menu-item key="11">option11</a-menu-item> <a-menu-item key="12">option12</a-menu-item> </a-sub-menu> </a-menu> </a-layout-sider> <a-layout-content :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }" > <strong>Using ref for data binding results:</strong><p></p> {{ebooks1}} <p></p> <pre> {{ebooks1}} </pre> <strong>Using ReactiveF for data binding results:</strong><p></p>{{ebooks2}} <p></p> <pre> {{ebooks2}} </pre> </a-layout-content> </a-layout> </template> <script lang="ts"> import { defineComponent,onMounted,ref,reactive,toRef} from 'vue'; import axios from 'axios'; export default defineComponent({ name: 'Home', setup(){ console.log('set up'); //Use ref for data binding const ebooks=ref(); // Use reactive data binding const ebooks1 = reactive({books:[]}) onMounted(()=>{ axios.get("http://localhost:8888/ebook/list?name=spring").then(response =>{ console.log("onMounted"); const data=response.data; ebooks.value=data.content; ebooks1.books=data.content; }) }) return { ebooks1: ebooks, ebooks2:toRef(ebooks1,"books") } } }); </script> Knowledge points: Need to import Recompile, start the service, and see the results as follows: 3. Final Thoughts The sense of accomplishment that front-end development gives people is more direct, because you can see it intuitively, unlike the business logic code in This is the end of this article about using Vue3 for data binding and displaying list data. For more relevant Vue3 data binding and displaying list data content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL password contains special characters & operation of logging in from command line
>>: How to use docker to deploy dubbo project
Table of contents Preface 1. Install Docker 2. In...
When processing batch updates of certain data, if...
Table of contents Preface Core - CancelToken Prac...
one. wget https://dev.mysql.com/get/mysql57-commu...
When a web project gets bigger and bigger, its CS...
Promise is a new solution for asynchronous progra...
question: My blog encoding is utf-8. Sometimes whe...
In this chapter, we will start to operate redis i...
Preface: Recently, I encountered a management sys...
Function: Jump to the previous page or the next p...
I recently encountered a problem at work. There i...
Table of contents Preface sql_mode explained The ...
Effect picture (if you want a triangle, please cl...
Table of contents 1 Install Docker in Baota Softw...
1. Introduction to mysqldump mysqldump is a logic...