Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Point of Vue

A Point of Vue

In this talk, Nathan will be giving us an overview of Vue.js, how you can use it in your project and how it works in comparison to other JS frameworks.

Avatar for Nathan Dunn

Nathan Dunn

February 20, 2019
Tweet

More Decks by Nathan Dunn

Other Decks in Programming

Transcript

  1. What is Vue? • “The Progressive JavaScript Framework” • Incrementally

    adoptable • Can also be used for SPAs • “Friendlier” choice for front-ends
  2. What is a component? • Isolated part of your application

    • Reusable • More reuse should mean less code to maintain • Control behaviour with props and events
  3. Vue Components <div id="root"> <message /> </div> Vue.component('message', { template:

    '<p>My name is: {{ name }}</p>', data: () => ({ name: ‘Nathan’, }) });
  4. Data Binding • Vue supports two-way data binding • The

    local state is held in data • You can add v-model to form elements to update the state in the component
  5. Templating • Vue has its own templating language • Uses

    {{ }} syntax for displaying data • v-if, v-else-if, v-else • v-for
  6. Templating - v-if <div id="root"> <input type="checkbox" v-model="show" /> <div

    v-if="show">Now you see me...</div> <div v-else>Now you don't...</div> </div> new Vue({ el: "#root", data: { show: false, } })
  7. Templating - v-for <div id="root"> <div v-for="organiser in organisers">{{ organiser

    }}</div> </div> new Vue({ el: "#root", data: { organisers: [ 'Jason', 'Ricky', 'Graeme' ] } })
  8. Props Validation Vue.component('message', { props: { name: { type: String,

    required: true }, }, template: `<div>Hello, {{ name }}</div>`, })
  9. Receiving Events <div id="root"> <message @message="announce" /> </div> new Vue({

    el: "#root", methods: { announce(message) { alert(message); } } })
  10. Computed Properties new Vue({ el: '#root', data: { message: 'Hello

    JSNE!', }, computed: { reversedMessage() { return this.message.split('').reverse().join('') } } })
  11. Single File Components <template> <div>Hello, {{ name }}</div> </template> <script>

    export default { props: ['name'], } </script> <style> h1 { font-size: 1.5rem; } </style>
  12. Vuex • Vue’s version of Redux • Provides a “single

    source of truth” (state) for your application’s data • Allows components stay up-to-date without props and events
  13. Conclusion • It’s an exciting time to be using Vue!

    • Expanding community • Growing beyond the web... • Vue.js 3