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 1. Truncate operation 1.1 What ...
1. To optimize the query, try to avoid full table...
Nowadays, the screen resolution of computer monit...
The effect diagram is as follows: <!DOCTYPE ht...
This article example shares the specific code of ...
Preface Previously, I talked about the problem of...
When we want to use a new CSS feature, we always ...
<br />Looking at this title, you may find it...
The following questions are all based on the Inno...
Table of contents Preface Project Design rear end...
Table of contents 1. Principle of animation funct...
1. Time types are divided into: 1. Network time (...
First of all, you need to understand why you use ...
Table of contents 1. What is a prototype? 1.1 Fun...
This article uses the deep learning framework ker...