Skip to content

theguriev/vue-repeater

Folders and files

NameName
Last commit message
Last commit date
Sep 11, 2019
Feb 4, 2020
Sep 10, 2019
Jul 12, 2021
Sep 4, 2019
Sep 4, 2019
Sep 11, 2019
Feb 21, 2020
Sep 4, 2019
Jul 18, 2021
Jul 12, 2021
Sep 11, 2019

Repository files navigation

vue-repeater

GitHub license npm version Netlify Status

The VueJS repeater component allows you to create a set of sub components which can be repeated again and again whilst editing content!

Just try it Rendered Demo on a real projec

Install

yarn add vue-repeater or npm install --save vue-repeater

How it works

Start

Start

Reordering

Reordering

Add

Add

Remove

Remove

Duplicate

Duplicate

Real project (Beagl)

Real project (Beagl)

Usage

Basic example

./main.js - entry point

import Vue from 'vue'
import App from './App.vue'

import VueRepeater from 'vue-repeater'
import 'vue-repeater/dist/vue-repeater.css'
import address from './components/address'

Vue.config.productionTip = false
Vue.component('vue-repeater', VueRepeater)
Vue.component('test-address', address)

new Vue({
  render: h => h(App)
}).$mount('#app')

./components/address.js - Component inside repeater

<template>
    <div class="address">
        <div class="row">
          <label>Street</label>
          <input v-model="localAddress.street">
        </div>
        <div class="row">
          <label>City</label>
          <input v-model="localAddress.city">
        </div>
        <div class="row">
          <label>Zip</label>
          <input v-model="localAddress.zip">
        </div>
    </div>
</template>
<script>
export default {
  name: 'test-address',
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  computed: {
    localAddress: {
      get () { return this.value },
      set (localAddress) { this.$emit('input', localAddress) }
    }
  }
}
</script>

<style scoped lang="scss">
.address{
  display: flex;
  flex-direction: column;
}

.row{
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

label{
  text-align: left;
  margin-bottom: 4px;
}

input{
  height: 32px;
  border-radius: 4px;
  border: 1px solid var(--def-border-base);
}
</style>

./App.vue - application component

<template>
  <div id="app">
    {{ fields }}
    <vue-repeater v-model="fields"></vue-repeater>
  </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
      fields: [
        {
          name: 'test-address',
          value: {}
        }
      ]
    }
  }
}
</script>

<style lang="scss">
#app {
  width: 900px;
  margin: 100px auto;
}
</style>

Contacts

Telegram: https://t.me/therealguriev

Skype: live:gurev