Skip to content

Commit a745dff

Browse files
committed
Switch testapp to composition API (with script setup)
1 parent c3ec62f commit a745dff

File tree

2 files changed

+25
-52
lines changed

2 files changed

+25
-52
lines changed

examples/testapp/src/App.vue

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44
</div>
55
</template>
66

7-
<script>
7+
<script setup>
88
import JsonapiVuex from './components/JsonapiVuex.vue'
9-
10-
export default {
11-
name: 'App',
12-
components: {
13-
JsonapiVuex,
14-
},
15-
}
169
</script>
1710

1811
<style></style>

examples/testapp/src/components/JsonapiVuex.vue

+24-44
Original file line numberDiff line numberDiff line change
@@ -74,54 +74,34 @@
7474
</div>
7575
</template>
7676

77-
<script>
77+
<script setup>
78+
import { computed, ref } from 'vue'
79+
import { useStore } from 'vuex'
7880
import { status, utils } from '../../../../src/jsonapi-vuex'
7981
80-
export default {
81-
name: 'JsonapiVuex',
82-
data: () => {
83-
return {
84-
searchResult: {},
85-
delWidgetId: undefined,
86-
postWidget: {
87-
_jv: {
88-
type: 'widget',
89-
},
90-
},
91-
}
92-
},
93-
computed: {
94-
sessions() {
95-
return status.status
96-
},
97-
widgets() {
98-
return this.$store.getters['jv/get']('widget')
99-
},
100-
widget1() {
101-
return utils.deepCopy(this.$store.getters['jv/get']('widget/1'))
102-
},
103-
},
104-
created() {
105-
status.run(() => this.$store.dispatch('jv/get', 'widget'))
82+
const store = useStore()
10683
107-
status
108-
.run(() => this.$store.dispatch('jv/search', 'widget'))
109-
.then((res) => {
110-
this.searchResult = res
111-
})
112-
},
113-
methods: {
114-
patchRecord(record) {
115-
this.$store.dispatch('jv/patch', record)
116-
},
117-
postRecord(record) {
118-
this.$store.dispatch('jv/post', record)
119-
},
120-
deleteRecord(id) {
121-
this.$store.dispatch('jv/delete', 'widget' + '/' + id)
122-
},
84+
let searchResult = ref({})
85+
let delWidgetID = ref()
86+
let postWidget = ref({
87+
_jv: {
88+
type: 'widget',
12389
},
124-
}
90+
})
91+
92+
const sessions = computed(() => status.status )
93+
const widgets = computed(() => store.getters['jv/get']('widget') )
94+
const widget1 = computed(() => utils.deepCopy(store.getters['jv/get']('widget/1')))
95+
96+
const patchRecord = ((record) => store.dispatch('jv/patch', record))
97+
const postRecord = ((record) => store.dispatch('jv/post', record))
98+
const deleteRecord = ((id) => store.dispatch('jv/delete', 'widget' + '/' + id))
99+
100+
store.dispatch('jv/get', 'widget')
101+
store.dispatch('jv/search', 'widget')
102+
.then((res) => {
103+
this.searchResult = res
104+
})
125105
</script>
126106

127107
<style scoped></style>

0 commit comments

Comments
 (0)