v-for

Vuejs toggle class in v-for

情到浓时终转凉″ 提交于 2019-12-23 02:43:04
问题 I'm making a list of items with v-for loop. I have some API data from server. items: [ { foo: 'something', number: 1 }, { foo: 'anything', number: 2 } ] and my template is: <div v-for(item,index) in items @click=toggleActive> {{ item.foo }} {{ item.number }} </div> JS: methods: { toggleActive() { // } } How can i toggle active class with :class={active : something} ? P.S I don't have boolean value in items 回答1: You can try to implement something like: <div v-for="(item, index) in items" v

v-for and v-if not working together in vue.js

杀马特。学长 韩版系。学妹 提交于 2019-12-19 06:33:30
问题 A form is used to submit text and two options which tell vue which column to display the text in. When the col2 radio button is checked the submitted text should display in column 2. This is not happening, on column 1 text is displaying. I have two radio buttons which should pass the value 'one' or 'two' to a newInfo.option On submnit a method pushed the form data to the array 'info'. <input type="radio" id="col1" value="one" v-model="newInfo.col"> <input type="radio" id="col2" value="two" v

v-for and v-if not working together in vue.js

痞子三分冷 提交于 2019-12-19 06:31:15
问题 A form is used to submit text and two options which tell vue which column to display the text in. When the col2 radio button is checked the submitted text should display in column 2. This is not happening, on column 1 text is displaying. I have two radio buttons which should pass the value 'one' or 'two' to a newInfo.option On submnit a method pushed the form data to the array 'info'. <input type="radio" id="col1" value="one" v-model="newInfo.col"> <input type="radio" id="col2" value="two" v

How to make v-for :key unique?

冷暖自知 提交于 2019-12-13 03:46:48
问题 I am having issues with items not properly adding/deleting from array, and I know it is because I need to be using something unique for my :key property. My app renders with a grid-item labeled Step:0 , if I create a Step 1 and Step 2 , and then I delete Step 1 , and add another step, then both the step 1 and new step 2 drag with each other at the same time. Currently my key is index for troubleshooting purposes, but I want my key to be step.uuid I have added a library with the function

for loop through array and bind class to element class attribute in vuejs

≯℡__Kan透↙ 提交于 2019-12-12 05:19:40
问题 I am trying to bind classnames into the class attribute with vuejs looping through an array like this: Here I pass the method call in a :class="paymentTypeClass(value)" to bind to the vue template like so: <li v-for="card in paymentType" class="o-pf-list__item" :class="paymentTypeClass(value)"> {{ card }} </li> new Vue ({ el: '#app', data: { paymentType: ['paymentType1', 'paymentType2', 'paymentType3', 'paymentType4', 'paymentType5'] }, methods: { functionName: function(value) { var i = 0;

Vue three columns of checkboxes in Bootstrap 4

六眼飞鱼酱① 提交于 2019-12-11 11:13:27
问题 Can anyone help me here with a 3 column layout via vue-js in bootstrap-4. I want to get my checkboxes displaying as 3 columns. The users are in order and I want the order going down the first column, then down the second and finally the third. <div v-for="(user, index) in users"> <div class="{'controls' : (index % (users.length/3)===0)}"> <input type="checkbox" :id="'user_'+user.id" :value="user.id" class="form-check-input" v-model="form.checkedUsers"> <label class="form-check-label" for="

Undefined Behavior with v-for and custom components

会有一股神秘感。 提交于 2019-12-11 05:49:14
问题 First off, please excuse the awful code (we don't have time to fix right now). I know eval is horrible, but for our purposes it was the only thing that worked for us this easily. This is how we add and remove the rows: methods: { addRow: function() { let lastRow = eval(`this.$parent.json${this.path}[this.$parent.json${this.path}.length - 1]`); lastRow = Object.assign({}, lastRow); eval(`this.$parent.json${this.path}.push(lastRow)`); this.$forceUpdate(); }, removeRow: function(index) { //eval(

Vue.js - Pass in Multiple Props to Child in V-For

一个人想着一个人 提交于 2019-12-10 16:36:34
问题 I'm trying to create a table with collapsible columns, but can't get the table body to collapse with the headers. Here's a fiddle which makes it clear what I'm trying to do: https://jsfiddle.net/ufw4f5qc/9/ and here's a fiddle what I tried which is producing an error: https://jsfiddle.net/oafw74hz/2/ The issue is most likely to do with scope of child and parent. I'm passing in a variable from parent to child using props, but it seems like the child does not take it. Am I binding the prop

Vue Js - Loop via v-for X times (in a range)

蹲街弑〆低调 提交于 2019-12-03 04:02:25
问题 How can I repeat a loop via v-for X (e.g. 10) times? // want to repeat this (e.g.) 10 times <ul> <li v-for="item in shoppingItems"> {{ item.name }} - {{ item.price }} </li> </ul> The documentation shows: <ul> <li v-for="item in 10">{{ item }}</li> </ul> // or <li v-for="n in 10">{{ n }} </li> // this doesn't work <li v-for="item in 10">{{ item.price }}</li> but from where does vue know the source of the objects? If I render it like the doc says, I get the number of items and items, but

v-for and v-if not working together in vue.js

五迷三道 提交于 2019-12-01 16:36:22
A form is used to submit text and two options which tell vue which column to display the text in. When the col2 radio button is checked the submitted text should display in column 2. This is not happening, on column 1 text is displaying. I have two radio buttons which should pass the value 'one' or 'two' to a newInfo.option On submnit a method pushed the form data to the array 'info'. <input type="radio" id="col1" value="one" v-model="newInfo.col"> <input type="radio" id="col2" value="two" v-model="newInfo.col"> This data is being pushed to the array 'info' correctly and I can iterate through