Vuejs

Subscribe to Vuejs feed
most recent 30 from stackoverflow.com 2017-09-14T21:10:11Z
Updated: 7 years 1 week ago

How to make a url-link from a button in Quasar version ^0.14

Sat, 2017-09-09 11:59

In Quasar version 0.13 the way to do it was:

<router-link v-bind:to="'/myurladdress'" tag='button' class='primary'>Link-name</router-link>

In the docs of of Quasar version 0.14.2 I merely find that your write a function on the button click event..?!

Categories: Software

Add Pagination to VueJS Gird Component Example

Sat, 2017-09-09 10:16

https://vuejs.org/v2/examples/grid-component.html

Does anyone has a paginantion feature for the grid component example in VueJS website?

Categories: Software

Any easier way to access nested object properties in Vue template?

Sat, 2017-09-09 10:09

It's convenient to group data into nested object properties. By doing this, we don't have to collect properties from the data field into an entity for later use. As in the following example,

var demo = new Vue({ el: '#demo', data: { level1: { level2: { level3_1: 'Hello', level3_2: 'world' } } } }) <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.min.js"></script> <div id="demo"> <div class="person"> <h3>{{ level1.level2.level3_1 }}</h3> <p>{{ level1.level2.level3_2 }}</p> </div> </div>

However, it's really overkill having to type the "level1.level2" prefix in order to get to the level3_x field. It'll be very cumbersome if there're loads of level3 fields.

I wonder if there is any way that I can save the work for typing level1.level2 over and over again. Does the template have any syntax so that some section is under the scope of "level1.level2"? Does Vue provide any support so that in this case the prefix "level1.level2" is assumed?

Categories: Software

Monaca app does not show any changes

Sat, 2017-09-09 10:08

I have developed an App based on vue.js using monaca, onsenUI and cordova. It works on my computer but when I send the project to my friend's computer, any change he made doesn't show after running monaca preview. Every dependencies and requirements are installed properly. Please help me out with the issue.

Categories: Software

Apps built on Monaca not showing changes

Sat, 2017-09-09 08:38

I have developed an app based on monaca, onsenUI and cordova. It works on my computer but when I send the project to my friend's computer, any change he made doesn't show after running monaca preview. Every dependencies and requirements are installed properly. Please help me out with the issue.

Categories: Software

In nuxt.js (vue.js), no parameters are passed in refresh (F5)

Sat, 2017-09-09 08:07

I am using nuxt.js.

Loads data from asyncData () of page component to axios.

async asyncData (context) { const name = context.route.params.name const response = await axios.get ('/ users /' + name) return { user: response.data.info } }

Navigate to when navigating to this page and the above code will work fine.

However, if you refresh (F5) on this page component,

const name = context.route.params.name

Gets the data in name.

const response = await axios.get ('/ users /' + name)

No parameter is passed in name.

That is, parameters are not passed to axios, and the server side does not receive param values.

To solve the above problem, the data was loaded from mounted () to axios.

Why does asyncData cause problems?

Categories: Software

Showing ADS in vuejs el

Sat, 2017-09-09 07:44

As we know, if we put <script> tag in the "el" vuejs, there will showing an error.. It's make me can't put any ads in vue el

For example:

new Vue({ el: '#app', data: { message: 'Hello Vue.js!' } }) <script src="https://unpkg.com/vue@2.4.2/dist/vue.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="app"> {{ message }} <script data-cfasync='false' type='text/javascript' src='//p31898.clksite.com/adServe/banners?tid=31898_118905_0'></script> </div>

  • Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as , as they will not be parsed.

so is it impossible to put Ads in Vue el?

Categories: Software

API design guideline for Vue.js integration

Sat, 2017-09-09 06:18

I am a backend developer and the frontend will be using Vue.js (not exist yet).

I am curious if standard restful API design already work nicely, or do I need special consideration when I am designing the API?

Categories: Software

Vue.js passing item in items to component as prop: will I be modifying prop?

Sat, 2017-09-09 03:31

New to Vue.js. From the docs, one simple example is to use components to render each item in a list, like this:

<todo-item v-for="item in groceryList" v-bind:todo="item" v-bind:key="item.id"> </todo-item> Vue.component('todo-item', { // The todo-item component now accepts a // "prop", which is like a custom attribute. // This prop is called todo. props: ['todo'], template: '<li>{{ todo.text }}</li>' }) var app7 = new Vue({ el: '#app-7', data: { groceryList: [ { id: 0, text: 'Vegetables' }, { id: 1, text: 'Cheese' }, { id: 2, text: 'Whatever else humans are supposed to eat' } ] } })

(Source: https://vuejs.org/v2/guide/index.html#Composing-with-Components)

My question is: what is the correct way of changing, for example, a todo text?

My initial idea was to use <input v-model="todo.text"> in the component template. And it works. I find this nice because it updates the array of to-dos in the root component data attribute, which means I don't have to write an event to make the changed data bubble up.

But there's a problem. Reading on the docs in components, I saw this:

All props form a one-way-down binding between the child property and the parent one: when the parent property updates, it will flow down to the child, but not the other way around. This prevents child components from accidentally mutating the parent’s state, which can make your app’s data flow harder to reason about. In addition, every time the parent component is updated, all props in the child component will be refreshed with the latest value. This means you should not attempt to mutate a prop inside a child component. If you do, Vue will warn you in the console.

If I understood this correctly, I should NOT try to change the todo text the way I did, because even tough it works, I'm changing a prop inside a child component (since each todo is passed to a child component via a prop).

But the documentation clearly says that Vue would warn me against this practice in the console, but I see no warnings.

Also, if this is not a best practice, how should I make a change in the to-do name correctly?

Categories: Software

Bind Vue-switch value to data prop

Sat, 2017-09-09 00:28

I am using vue-switch that toggles on and off and I need to know what state it's in. According to the documentation at https://www.npmjs.com/package/vue-switch I am just supposed to use :value.sync="toggle" in the switch component with a data property called 'toggle', which I've done. I'm getting the following error:

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "value" vue switch found in ---> <Switcher> at E:\Dev\BackgroundCheck.Members\front-end\node_modules\vue-switch\switch.vue

My HTML:

<switcher size="lg" color="green" :value.sync="toggle"></switcher>

My JS:

<script> import mySwitch from 'vue-switch'; export default { name: 'BackgroundReports', components: { 'switcher': mySwitch }, computed: { report() { return this.$store.getters.currentReport }, isBeingMonitored() { return this.$store.getters.isBeingMonitored } }, mounted() { this.toggle = this.isBeingMonitored; } } </script>

The switch.vue code:

<template> <div :class="className" @click="onClick"> <span class="open">{{ openName }}</span> <span class="close">{{ closeName }}</span> </div> </template> <script> 'use strict'; export default { props: { value: { default: true, twoWay: true }, size: { type: String, default: 'md中' }, // blue red green orange color: { type: String, default: 'red' }, openValue: { default: true }, closeValue: { default: false }, openName: { type: String, default: 'ON' }, closeName: { type: String, default: 'OFF' }, disabled: { type: Boolean, default: false } }, computed: { className() { let { value, openValue, closeValue, size, color, disabled } = this; return { 'vue-switch': true, 'z-on': value === openValue, 'z-disabled': disabled, ['s-' + size]: true, ['c-' + color]: true }; } }, methods: { onClick() { let { disabled, value, openValue, closeValue } = this; if (!disabled) { if (openValue === value) { this.value = closeValue; } else { this.value = openValue; } } } } } </script>
Categories: Software

How to reuse a constant defined inside a vie component

Fri, 2017-09-08 23:24

So I am in a situation where I want to create a const value inside mounded(). And want to use this const value inside the methods of a vie component.

export default { name : 'app', data(){ }, mounted(){ // Constant refThis is defined here which gets the reference to this vue component const refThis = this; }, methods:{ useThisRef() { // I want to be able to use the refThis here } } }
Categories: Software

Update v-for When Data Is Added To Array - VueJS

Fri, 2017-09-08 23:14

I'm kinda new to VueJS so I was hoping to get some help. I'm currently returning an array of json objects from a PHP file.

Example:

<?php /* Returns an array similar to this: [ {name: 'foo'}, {name: 'bar'}, {name: 'banana'} ] */ echo json_encode(array_values($array)); ?>

And I'm appending this array of objects to an already existing array of objects in Vue:

axios.post('http://localhost/get_array.php').then(response => { // Append returned array to already existing array for (var i = 0; i <= response.data.length - 1; i++) { this.existingArray.push(response.data[i]) } }).catch(e => { console.log("Error") })

Right now I'm appending the data with a for loop but I was wondering if VueJS has an in-built function that does this automatically without having to use the for loop?

Categories: Software

How to pass PHP variable to Vue directive

Fri, 2017-09-08 22:58

Looking for some help with Vue and WordPress:

I’m trying to get Vue and PHP to talk with each other and having some trouble. Currently, in the project, we’re creating an anchor for each “resource”

<a v-if="resource.pdf_color" :href="resource.pdf_color.url" download class="btn btn-with-icon icon-file-check" data-toggle="tooltip" data-placement="top" title="Color Download"> <label>Color Download</label> </a>

However, we would like to use a WP plugin called “Easy Media Download” to limit number of resources downloaded (we’re trying to minimize members signing for one month to download all materials then canceling service).

I’m trying to figure it out how to be able to call the $url resource.pdf_color.url inside the shortcode do_shortcode( '[easy_media_download url=" $url "]' ) and then bind it to the anchor element inside the href argument. I’ve tried a few things but haven’t had much luck.

Any suggestions or ideas on how to solve this?

Categories: Software

Vuejs, change store (Vuex) inside of Watcher

Fri, 2017-09-08 21:34

how can I call method or mutation in Vuex from watcher?

this.$store is undefined and if I try to call method have error function is not defined?

Code:

watch: { formData: { handler: () => { console.log(this); this.SetStoreForm(); }, deep: true } }

Method:

methods: { SetStoreForm() { this.$store.commit('SetProductForm', this.formData); } }

Thanks

Categories: Software

Change route with vue- <router-link>

Fri, 2017-09-08 20:52

I have a <router-link to = "/ endreco / test">, but I need to perform the same behavior on a vue-material tab, something like this: <md-tab md- icon = "books"> .. to change my route, same as the href = ""

What should I do?

I'm using vue.js, the vue-router to control routes and style with vue-material

Categories: Software

vue keydown event on slides

Fri, 2017-09-08 20:21

this is a part my simple slides demo by vue

<div class="slide" @mouseover="clearinv" @mouseout="runinv" @keydown.39="goto(nextIndex)" @keydown.37="goto(prevIndex)">

Like that, I want to touch the keydown event with left(37) & right(39)

and touch the goto(nextIndex) function,but while I pressing the key, the slide won't listen my keydown event...

I have considered that window.addEventListener('keydown',(e)=>{...}) in the mounted hook, and it can solve this.

But, I think it will be the better solution in Vue.

How can I solve this?

-

this is the full one on CodePen

Categories: Software

how to get a reference to the specific v-model in form

Fri, 2017-09-08 19:58

I'm new to Vue2 and am trying to to get a reference to a model's value in a form to be passed to a method. I have:

<div v-for="n in maxLength"> <input v-model='price.matrix_prices[n]' /><div @click="fillPrices(?)">set all to this price</div> {{n}}</div>

The matrix_prices is a hash with specified values. Lets say someone fills in 8 in the input model, how would I get a reference so that ? would be eight?

Categories: Software

Vue js sharing data between child components

Fri, 2017-09-08 19:34

I'm trying to send data from one component to another one without any success. I have one parent component App.vue and two child components Base.vue and Ingredients.vue. Mainly I' would like to send dynamic {{selectedBase.price}} (which is updated every time you select/deselect the option) from Base component to Ingredients component and being rendered on Ingredients component dynamically.

I imported and defined my-base and my-ingredients components on the main.js file

//App.vue <v-app light> <main> <v-container fluid> <v-flex xs12 sm6 offset-sm3> <my-base ></my-base> </v-flex> <v-flex d-flex xs12 sm6 offset-sm3 class="text-xs-center"> <my-ingredients></my-ingredients> </v-flex> </v-container> </main> </v-app> //Ingredients.vue <v-layout row v-for="ingredient in ingredients" :key="ingredient.id"> <v-layout column> <v-flex xs6 offset-xs5> <v-checkbox class="text-xs-right" name="checkbox" color="light-blue lighten-2" v-bind:label="`${ingredient.name}`" v-model="ingredient.checked" light></v-checkbox> </v-flex> </v-layout> <v-layout column> <v-flex xs6 offset-xs5> <v-subheader>{{ingredient.price}} €</v-subheader> </v-flex> </v-layout> </v-layout> <v-divider></v-divider> <v-layout row wrap class="mb-3"> <v-layout column> <v-flex xs6 offset-xs3> <h3 class="headline mb-0">Total price:</h3> </v-flex> </v-layout> <v-layout column> <v-flex xs6 offset-xs4> <v-subheader> {{total}} €</v-subheader> </v-flex> </v-layout> </v-layout> <script> export default { data: () => ({ checked1: '', showCart: false, ingredients: [{ id: 1, name: "Mozzarella", price: 2, checked: '', }, { id: 2, name: "Cheddar", price: 2.0, checked: '', }, { id: 3, name: "Bacon", price: 2.25, checked: '', }, { id: 4, name: "Mushrooms", price: 1.6, checked: '', }, { id: 5, name: "Pepperoni", price: 2.5, checked: '', }, { id: 6, name: "Sucuk", price: 2.75, checked: '', }], }), computed: { total: function() { var total = 0; for (var i = 0; i < this.ingredients.length; i++) { if (this.ingredients[i].checked) { total += this.ingredients[i].price; } } return total; } } } </script> //Base.vue <v-layout row wrap primary-title v-for="base in bases" :key="base.id"> <v-layout column> <v-flex xs6 offset-xs3> <v-avatar size="80px" class="grey lighten-1"> <img :src="base.href" :class="{selected: selectedBase.id == base.id}" @click="selectedBase = base" alt="avatar"> </v-avatar> </v-flex> </v-layout> <v-layout column> <v-flex xs6 offset-xs4> <v-subheader>{{base.name}} {{base.price}}€ {{selectedBase.price}}</v-subheader> </v-flex> </v-layout> </v-layout> </v-card> </template> <script> export default { data() { return { selectedBase: {}, bases: [{ id: 1, name: "Margarita", price: 4, href: "../../static/margarita.jpg" }, { id: 2, name: "Salami", price: 6, href: "../../static/salami.jpg" }] } }, computed: { totalBase() { var totalBase = 0; for (var i = 0; i < this.bases.length; i++) { if (this.bases[i].selected) { totalBase += this.bases[i].price; } } return totalBase; }, methods: { getSelectedBase() { return this.selectedBase; } } } } </script>
Categories: Software

Vue.js - Registering the Chart Component via Webpack

Fri, 2017-09-08 19:23

I have a Vue.js app. I am trying to use the vue-charts package. I'm importing the chart module in my index.js file like this:

import chartJS from 'chart.js'; import VueCharts from 'hchs-vue-charts'; Vue.use(VueCharts);

Then, in my index.vue file, I have the following:

<template> <div class="page"> <h2>Hello</h2> <chartjs-line></chartjs-line> </div> </template> <script> export default { data() { return {}; } }; </script>

The word "Hello" appears just fine. For that reason, I know that my app is being properly mounted. However, the chart does not appear. When I look in the devtools window, I see the following error:

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

I assumed when I called Vue.use, the component would get registered. However, I'm clearly doing some wrong. Yet, I'm not sure what. How do I use the vue-charts components in my single file components?

Categories: Software

Vuejs event not working in firefox - fine in Chrome [on hold]

Fri, 2017-09-08 17:55

I have an event in vuejs

methods: { filterPeople: function filterPeople() { $(event.target).closest('li').addClass('active'); });

In firefox I get an error

TypeError: event is undefined mounted/< re/e.prototype.$emit filterPeople

Any idea why this does not work in FF

Categories: Software

Pages