- 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:

- 高校網絡道德教育研究
- INSTANT PhpStorm Starter
- 物聯網安全與深度學習技術
- JBoss EAP6 High Availability
- Go Web Scraping Quick Start Guide
- 互聯網安全的40個智慧洞見:2014年中國互聯網安全大會文集
- 大話社交網絡
- Wireshark網絡分析就這么簡單
- 雷達饋線技術
- 智慧光網絡:關鍵技術、應用實踐和未來演進
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- 人人都該都懂的互聯網思維
- 一本書讀懂物聯網
- 基于IPv6的家居物聯網開發與應用技術
- Hands-On Docker for Microservices with Python