In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how vue loads local json data". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how vue loads local json data.
Vue loads local json data json data is stored in a static folder except static
This method has not come out yet. If a great god knows, can you guide one or two?
Json data is stored in a static static folder
1. Write json data and write json data according to this format
2. Install axios installation method: npm install axios
3. Configure axios to reference axios in main.js, as shown in the following figure
4. You can call json data, or you can add: console.log (this.fieldParams) prints the data in the console
Form Code:
The realization of the function of reading local json file and paging display
The contents of the local json file are read through the axios asynchronous loading technology, and the data is paged on the h6 page through vue.js processing (here paged with 3 lines of data)
Student.json data are as follows: {"stuId": 1, "stuName": "Li Hua", "stuSex": "male", "stuAge": 20}, {"stuId": 2, "stuName": "Zhang Guowei", "stuSex": "male", "stuAge": 22}, {"stuId": 3, "stuName": "Liu Yan", "stuSex": "female", "stuAge": 19}, {"stuId": 4, "stuName": "Li Xiaoyan", "stuSex": "female" "stuAge": 22}, {"stuId": 5, "stuName": "Zhang Peng", "stuSex": "male", "stuAge": 26}, {"stuId": 6, "stuName": "Li Ye", "stuSex": "female", "stuAge": 20}, {"stuId": 7, "stuName": "Qian Guoqiang", "stuSex": "male", "stuAge": 21}, {"stuId": 8, "stuName": "Zhang San", "stuSex": "male" "stuAge": 22}, {"stuId": 9, "stuName": "Tang Yumin", "stuSex": "male", "stuAge": 25}, {"stuId": 10, "stuName": "Maria", "stuSex": "female", "stuAge": 21}, {"stuId": 11, "stuName": "Li Jiaming", "stuSex": "male" "stuAge": 21}] H6 code is as follows: serial number, name, sex, age {{student.stuId}} {{student.stuName}} {{student.stuSex}} {{student.stuAge}}
< {{ index+1 }} >Css style [v-cloak] {display: none;} ul {margin-left: 20px;} ul li {float: left; list-style: none; background-color: aqua;} ul li a {text-decoration: none; padding: 5px 15px; color:black; border: 1px solid white;} a:hover {background: tomato } js code / / create a Vue instance and get ViewModel var app = new Vue ({el:'# app', data: {list: [], pageSize:3,// page size currentPage:0 / / current page number}, / * data * / mounted () {/ / load json data axios.get ('/ json/student.json') asynchronously {}) .then (function (response) {app.list=response.data });}, / * Auto load function * / methods: {/ / previous page nextPage: function () {if (this.currentPage = = this.pageNumber-1) return; this.currentPage++;}, / / next page prePage: function () {if (this.currentPage = = 0) return; this.currentPage-- }, / / Page number thisPage: function (index) {this.currentPage = index;}}, / * execute trigger function * / computed: {/ / paging data stuData: function () {let left = this.currentPage*this.pageSize Let right = Math.min ((this.currentPage+1) * this.pageSize, this.list.length) return this.list.slice (left, right); / / take out a page of data}, / / how many pages of pageNumber: function () {if (this.list.length)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.