How to Implement Vue-select in Our Project

in #utopian-io9 years ago (edited)

20160827220748.jpg
image-source
This time I will share tutorial how to use select in vue.js by using vue-select. In a web application of course we often use a lot of data. and with vue-select we can display the data like select box but more elegant and practical for the user.

What Will I Learn?

  • Install Package with Npm
  • How to Implement Vue-select

Requirements

  • Install Nodejs
  • Install Vue Cli
  • Basic Javascript es6 & basic Vue

Difficulty

  • Basic

Install Package with Npm

Before we start installing the vue-select package, make sure you have installed nodejs , so you can use Npm. to check its version npm -v
Screenshot_1.png
and now you can install the vue-select. Open your folder that has installed vue-cli. open command prompt . and then you can install .
npm install sagalbot/vue-select --save, for notes. i added --save: it's means you want to save in your package.json
Screenshot_3.png
Screenshot_2.png

How to Implement Vue-select

Create Component

The first step has been to create a simple component to make an example. The name of the component is select.vue

<template>
  <div class="root">
     <h3>Learn Vue-select</h3>
  </div>
</template>
<script>
export default {
  data () {
    return {
    }
  },
}
</script>
(html comment removed:  Add "scoped" attribute to limit CSS to this component only )
<style scoped>
.root{
    margin: 0 auto;
    max-width: 600px;}
</style>

Import Component Vue-select

We will import the Vue-select as locally.
import vSelect from "vue-select". And then registered the component in property components:{vSelect }

<template>
  <div class="root">
     <h3>Learn Vue-select</h3>
  </div>
</template>
<script>
import vSelect from "vue-select"
export default {
  data () {
    return {
    }
  },
  components:{
    vSelect
  }
}
</script>
(html comment removed:  Add "scoped" attribute to limit CSS to this component only )
<style scoped>
.root{
    margin: 0 auto;
    max-width: 600px;}
</style>

Use Vue In Our Template

We can add vue-select in our component like this.
< v-select : options ="fruits" ></ v-select > : This how we add Vue-select in our component, there is v-bind or : in this component,
options is props we pass to component vue-select. This is the provision of the vue-select library.
Add data locally in our component.


data () {
    return {
      fruits:["Mangoo","Apple","Orange","Melon","Pineapple","Lecy","Blueberry"]
    }
  },

We add data fruits and its type as array. In this tutorial , I will add array with the name of the fruit. After all its done then we can run our program. npm run dev

Screenshot_6.png

Screenshot_7.png

And finally we successfully apply vue-select in our component. there are some other options please check in vue-select documentation https://sagalbot.github.io/vue-select/. So much of me, hopefully this tutorial can help you. thank you



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

  • Was a little short but you came in, taught what you wanted to and left. Really like that.
  • Try to keep the length a bit longer next time ; )

You can contact us on Discord.
[utopian-moderator]

Thank you @umais i will do better next time

Thanks for understanding!

Hey @alfarisi94 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.098
BTC 64388.69
ETH 1869.17
USDT 1.00
SBD 0.38