- Vue.js 2 Design Patterns and Best Practices
- Paul Halliday
- 265字
- 2021-06-24 18:33:02
Mobile development
When it comes to developing mobile applications, projects such as Angular and React are great choices for developing mobile-first applications. The success of the NativeScript, React Native, and Ionic Framework projects have boosted the significant popularity of these frameworks. For instance, Ionic Framework currently has more stars than Angular on GitHub!
Vue is making waves in this area with projects such as NativeScript Vue, Weex, and Quasar Framework. All of the listed projects are relatively new, but it only takes one to truly spike the popularity of Vue in production even further. Using NativeScript Vue as an example, it only takes 43 lines of code to create a cross-platform mobile application that connects to a REST API and displays the results on screen. If you'd like to follow along with this yourself, run:
# Install the NativeScript CLI npm install nativescript -g # New NativeScript Vue project tns create NSVue --template nativescript-vue-template # Change directory cd NSVue # Run on iOS tns run ios
Then, we can place the following inside of our app/app.js:
const Vue = require('nativescript-vue/dist/index'); const http = require('http'); Vue.prototype.$http = http; new Vue({ template: ` <page>
<action-bar class="action-bar" title="Posts"></action-bar>
<stack-layout>
<list-view :items="posts">
<template scope="post">
<stack-layout class="list">
<label :text="post.title"></label>
<label :text="post.body"></label>
</stack-layout>
</template>
</list-view>
</stack-layout>
</page>
`, data: { posts: [] }, created(args) { this.getPosts(); }, methods: { getPosts() { this.$http .getJSON(`https://jsonplaceholder.typicode.com/posts`) .then(response => { this.posts = response.map( post => { return { title: post.title, body: post.body } } ) }); } } }).$start();
If we then run our code, we can see a list of posts. You'll notice that our Vue code is declarative, and we have the power of larger frameworks at our disposal with much less code:

- EJB 3.1從入門到精通
- 6G潛在關(guān)鍵技術(shù)(下冊(cè))
- 高校網(wǎng)絡(luò)道德教育研究
- 新一代物聯(lián)網(wǎng)架構(gòu)技術(shù):分層算力網(wǎng)絡(luò)
- Yii Application Development Cookbook(Second Edition)
- 新手易學(xué):新手學(xué)淘寶開(kāi)店
- 6G:面向2030年的移動(dòng)通信
- 通信十年:擁抱互聯(lián)網(wǎng)
- 異構(gòu)蜂窩網(wǎng)絡(luò)關(guān)鍵理論與技術(shù)
- 信息技術(shù)安全評(píng)估準(zhǔn)則:源流、方法與實(shí)踐
- 想象的互動(dòng):網(wǎng)絡(luò)人際傳播中的印象形成
- 走近奇妙的物聯(lián)網(wǎng)
- 一本書讀懂移動(dòng)物聯(lián)網(wǎng)
- 深入淺出計(jì)算機(jī)網(wǎng)絡(luò)
- 網(wǎng)絡(luò)信息編輯項(xiàng)目化實(shí)操教程(第2版)