All Useful Properties when Initializing Vue

Struggling to copy/paste all useful properties when initializing Vue? Looking to see what else Vue can do for you? Here’s the answer. We have seen how Vue can be used from CDN. Initializing Vue is simple enough - // main.js new Vue({ el: "#app" } }); The above code block will initialize Vue and load it to element with id app. As we have seen previously, we can use a bunch of properties during initialization and make Vue super useful. ...

Create a field with a simple date picker in Vue

Do not reinvent the wheel to create your own date picker component. Just use one of the existing components and praise those developers who share great things. I have historically struggled with date pickers and had finally settled in on a good date picker for Vuetify. Since most of my Vue projects are standardized on Materialize, that posed no issues. However, if I need to create something outside of Vuetify, the available options suddenly explode to my utter delight. I have not really dug deep - but the aptly named ‘vuejs-datepicker’ checks all the boxes. ...

Create a simple calculator using Vue from CDN

Let us create a dead simple calculator using Vue. Create basic structure As it was earlier, the basic structure just has two files - index.html and main.js. <!-- index.html --> <html> <body> <div id="app"> <h1>Lé Calculator</h1> <p> <input type="string" v-model="inputExpr" placeholder="Enter expression" style="width:80%;height:30px" /> </p> <p>Result:</p> <p>{{ result }}</p> </div> <script src="https://unpkg.com/vue"></script> <script src="./main.js"></script> </body> </html> We have followed a few fundamental principles to create two elements and bind them to Vue variables - nothing new. ...

Create a small to-do app including Vue from CDN

Let us create a small example to-do app using Vue from CDN. There is not going to be any backend for this application. Create basic structure The basic structure just has two files - index.html and main.js. <!-- index.html --> <html> <body> <div id="app"> <h5>Hello, {{ name }}</h5> <h1>Your To Dos</h1> </div> <script src="https://unpkg.com/vue"></script> <script src="./main.js"></script> </body> </html> Start playing around with Vue in main.js. console.log("hello world"); new Vue({ el: "#app", data() { return { name: "World!" }; } }); Above code is enough to make the application “usable”. Open index.html in your favourite browser that starts with the word for 🔥. ...

Three ways to include Vue in your projects

There are multiple ways of using VueJS - which should you use? VueJS is flexible and powerful - not a combination that you often see together. You can initiate and use Vue in more than one way in your app. Use in package with a build cycle This should be your preferred way of using Vue. First install Vue CLI globally - npm i -g @vue/cli The above command will install Vue CLI globally in your computer (in Windows - it is in C:\Users\<user>\AppData\Roaming\npm\). ...

eChart Display Issues in Tabs

I love Vue / Vuetify and use them quite often in my projects. I had to display charts in a couple of recent projects and my search led to v-charts. I was impressed with what the library could do - v-charts is a Vue wrapper for eCharts, the Baidu-developed chart library The v-charts library makes it really easy to use ECharts. Docs have improved significantly after transitioning to be an Apache incubator Charts are amazing. They are responsive and reactive without needing any additional work So then, I was within reach of nirvana in my ‘pursuit of excellence’ in development of typical data-driven applications.. .. until I came across an issue with displaying charts in tabs. ...

Easier Date Picker in Vuetify

Date pickers are straight forward, but can become laborious in Vuetify components. Look at how date pickers are implemented in Vuetify - they can cause minor trauma for a beginner. The efficient solution is to implement a custom component. Wrap menu + input box in that generic component, and use it everywhere. Or, just use v-datetime-picker. Get started Install v-datetime-picker in your Vue project. npm install --save vuetify-datetime-picker Add following in your main.js. ...

Input Field with Date Picker in Vuetify

Date pickers are straight forward to implement, but input fields with date pickers need a bit of decoration. What we need? An input field with a date picker that opens on click shows the selected date How do we create that? We start with the ‘date picker’ component in Vuetify. <template> <v-layout row wrap> <v-date-picker locale="en-in" :min="minDate" :max="maxDate" v-model="fromDateVal" no-title ></v-date-picker> </v-layout> </template> <script> export default { data() { return { fromDateVal: null, minDate: "2019-07-04", maxDate: "2019-08-30", }; }, }; </script> Bind value to fromDateVal. Specify locale, min & max dates. ...

Use SVGs directly in Vue

SVGs are optimized image files that bend to your will, er.. size. They stay sharp at various resolutions, are small in size, and can change colour through code! And, it is really easy to use them in Vue single file components. Consider this example of a tomato. <svg style="display:none;" version="1.1" class="hidden" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" > <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 51.679 51.679" id="tomato"> <path d="M40.47 8.458c-2.562-1.642-7.374-3.93-11.997-1.816a.67.67 0 0 1-.952-.607V1.786C27.522.804 26.855 0 26.04 0h-2.223c-.815 0-1.482.804-1.482 1.786v4.501a.67.67 0 0 1-.802.661c-1.877-.387-6.751-.989-11.412 1.795-.638.381-.268 1.381.464 1.247 2.17-.397 5.026-.67 6.956.092a.674.674 0 0 1 .124 1.189c-1.371.895-3.9 2.953-5.557 6.737-.282.644.51 1.221 1.053.774 2.117-1.744 5.6-4.107 8.554-3.726a.68.68 0 0 1 .607.68c-.03 1.982-.005 8.716 1.632 11.265a.675.675 0 0 0 1.117.035c1.043-1.433 3.304-5.233 3.211-11.167a.677.677 0 0 1 .697-.694c1.49.048 5.008.469 7.798 3.194.457.447 1.214.061 1.134-.573-.219-1.735-1.174-4.359-4.631-6.394-.525-.309-.436-1.095.155-1.24 1.194-.293 3.252-.572 6.644-.46.689.021.97-.873.391-1.244z" fill="#88c057" /> <path d="M41.248 9.99a.698.698 0 0 0-.314-.12c-.4-.049-.801-.095-1.201-.149-.143-.014-.287-.025-.429-.039-2.914-.048-4.743.206-5.846.474a.674.674 0 0 0-.175 1.244c3.457 2.035 4.411 4.659 4.63 6.393.08.634-.677 1.02-1.134.573-2.79-2.724-6.308-3.145-7.798-3.194a.676.676 0 0 0-.697.694c.092 5.934-2.168 9.734-3.211 11.167a.675.675 0 0 1-1.117-.035c-1.637-2.549-1.662-9.283-1.632-11.265a.681.681 0 0 0-.607-.68c-2.954-.382-6.437 1.982-8.554 3.726-.543.447-1.335-.13-1.053-.774 1.655-3.779 4.18-5.836 5.552-6.733a.674.674 0 0 0-.128-1.19 6.461 6.461 0 0 0-1.203-.324.735.735 0 0 0-.234-.004 57.35 57.35 0 0 0-7.119 1.411.718.718 0 0 0-.278.144C3.597 15.555.393 21.668.393 28.465c0 12.821 11.393 23.214 25.446 23.214s25.446-10.393 25.446-23.214c.001-7.537-3.937-14.235-10.037-18.475z" fill="#d13834" /> <path d="M5.791 34.636a.998.998 0 0 1-.861-.49A11.328 11.328 0 0 1 3.473 30a1 1 0 0 1 .844-1.135.991.991 0 0 1 1.135.844 9.457 9.457 0 0 0 1.199 3.418 1 1 0 0 1-.86 1.509zm-1.203-7.958a1 1 0 0 1-.999-1.069c.094-1.327.366-2.616.811-3.834a1.001 1.001 0 0 1 1.879.687 11.997 11.997 0 0 0-.694 3.285 1 1 0 0 1-.997.931z" fill="#ed7161" /> </symbol> </svg> You may have noticed that SVGs are simply a bunch of coordinates? Well, the above code is just an example. ...

Accept Multiple Props in a Vue Component

Vue enables you to define more than one prop against a component. See which component communication is effective and how props compare to Vuex Defining prop in a component is simple enough - <!-- Target.vue --> <template> {{ tinyInput }} <!-- display the prop --> </template> <script> export default { props: { tinyInput: { type: String, required: false } } }; </script> Just include additional prop to Target to accept more than one prop - <!-- Target.vue --> <template> {{ tinyInput }} {{ tinierIn }} <!-- display the prop --> </template> <script> export default { props: { tinyInput: { type: String, required: false }, tinierIn: { type: String, required: false } } }; </script> To do the same without using a single file component - ...