Skip to content

Commit

Permalink
using v-model and watch
Browse files Browse the repository at this point in the history
  • Loading branch information
St3Ko committed Feb 11, 2021
1 parent 7a36917 commit 3eae191
Show file tree
Hide file tree
Showing 2 changed files with 8,197 additions and 10 deletions.
8,176 changes: 8,174 additions & 2 deletions resources/dist/js/table_on_steroids-fieldtype.js

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions resources/js/TableOnSteroids.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<Table @input="handleTableInput" :value="value" />
<Table v-model="data" />
<label class="form-group-label mt-2 mb-1">Paste your CSV into this field:</label>
<textarea class="input-text w-full mb-2" v-model="csv" rows="4"></textarea>
<button class="btn btn-default mb-2 mr-1" @click="csvToJavascript">Process CSV Data</button>
Expand All @@ -9,13 +9,13 @@
</div>
</template>
<script>
import parse from 'csv-parse/lib/sync'
const Table = Vue.component('table-fieldtype')
export default {
mixins: [Fieldtype],
props: {
value: Array,
},
data() {
return {
csv: '',
Expand All @@ -26,10 +26,25 @@ export default {
components: {
Table,
},
methods: {
handleTableInput(data) {
this.update(data)
watch: {
// safe guard if value prop changes from outside
value: {
deep: true,
handler(data) {
this.data = data;
}
},
data: {
deep: true,
handler(data) {
this.update(data);
}
}
},
created() {
this.data = this.value;
},
methods: {
handleClearInput() {
this.csv = ''
},
Expand Down Expand Up @@ -57,7 +72,7 @@ export default {
}
result.push(line)
})
this.value = result
this.data = result
} catch (e) {
this.error = e.message
}
Expand Down

0 comments on commit 3eae191

Please sign in to comment.