Vuejs

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

Editing record within list, with dynamically defining children properties with VueJS

Mon, 2017-07-17 21:58

With VueJS, I am trying to create a generic component that would work with different types of records.

For instance, let's say I have user records:

var users = [ { UserID: 1, username: "pan",email:"peter.pan@neverland.com" }, { UserID: 2, username: "john",email:"john.doe@somewhere.com" } ];

And group records

var groups = [ { GroupId: 1, groupName: "Users", description: "Lorem ipsum ..." }, { GroupId: 2, groupName: "Admins", description: "Some people with super powers" } ];

I want to create a Vue component to edit those records, so it can be defined as such:

<record-editor v-bind:record="user[0]" title="Edit user"> <text-editor label="User name" property="username"></text-editor> <text-editor label="Email" property="email"></text-editor> </record-editor> <!-- For the binding syntax, I am not sure what should I use to bind to a record in the lists shown before --> <record-editor v-bind:record="groups[0]" title="Edit group"> <text-editor label="groupName" property="groupName"></text-editor> <text-editor label="Description" property="description"></text-editor> </record-editor>

Right now, what I have is:

(function() { var textEditor = Vue.component('text-editor', { template: "#text-editor", props: ['label', 'property'] }); var recordEditor= Vue.component('record-editor', { template: '#model-editor', props: ['title', 'record'] }); var vue = new Vue({ el:"#someContainer", data: { users : users, groups: groups } }) }()) <template id="text-editor"> <div> <label v-bind:for="property">{{label}}</label> <!-- need help figuring what to put in v-bind:value --> <input type="text" v-bind:name="property" v-bind:id="property" v-bind:value=""> </div> </template> <template id="record-editor"> <div> <h2>{{title}}</h2> <form> <slot></slot> </form> </div> </template>

So basically, what I am missing is how to bin to the elements in the list to edit them.

And how can I dynamically define properties for the sub components (text-editor).

Categories: Software

Passing props with programmatic navigation Vue.js

Mon, 2017-07-17 21:04

I have a Vue component that has a prop named 'title' e.g:

<script> export default { props: ['title'], data() { return { } } } </script>

I navigate to the component programmatically after a certain action is complete. Is there a way to programmatically route a user while also setting the prop value? I know you can create a link like this:

<router-link to="/foo" title="example title">link</router-link>

However, is there a way to do something like the following?

this.$router.push({ path: '/foo', title: 'test title' })

EDIT:

As suggested I've changed my route to the following:

{ path: '/i/:imageID', component: Image, props: true }

And the navigation to the following:

this.$router.push({ path: '/i/15', params: {title: 'test title' }})

However, my Image component (template - see below) still doesn't show any title.

<h1>{{ title}}</h1>

Is there anything that could be causing issues?

Categories: Software

Pass value from a component to the parent instance

Mon, 2017-07-17 19:53

I have a component named cartComponent with a data property cartCount that gets incremented whenever a new item is added to the cart.

I need to use that value to update the value in the template which is not a part of the component. Is this possible?

Here's is the script for my parent Vue instance:

new Vue({ el: "#cart-app", components: { cart: cartComponent }, data: { searchQuery: '', appliedFilters: ['Day 1'], purchaseData: json, cCount: 0 // CARTCOUNT; NEEDS TO BE UPDATED FROM COMPONENT } });
Categories: Software

Pages