2019/11/23
v-kansai mokumoku #3
2019/12/16
v-okinawa #3
import Vue from 'vue'
import CompositionApi from '@vue/composition-api'
Vue.use(CompositionApi)
import '@/plugins/composition-api.ts'
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
//
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
return (
//
)
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
interface PropsType {
participants: number,
mealName: string
}
export default createComponent({
setup(props: PropsType, ctx: SetupContext) {
//
}
})
interface Data {
[key: string]: unknown
}
interface SetupContext {
attrs: Data
slots: Slots
parent: ComponentInstance | null
root: ComponentInstance
emit: ((event: string, ...args: unknown[]) => void)
}
function setup(
props: Data,
context: SetupContext
): Data
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
// Get Route Params
const param = ctx.root.$route.params;
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
// Get state
const userStatus = ctx.root.$store.state.product.userStatus
// Use computed api
const filteredUserStatus = computed(
() => ctx.root.$store.state.product.userStatus
)
}
})
import Vue from 'vue'
export default Vue.extend({
data() {
return {
participants: 12,
meals: ['hamburger', 'ramen', 'pizza']
}
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
const participants = ref(12)
const meals = ref(['hamburger', 'ramen', 'pizza'])
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
const ReactiveData = reactive({
participants: 12,
meals: ['hamburger', 'ramen', 'pizza']
})
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
return {
state
}
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
return (
//
)
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
const AtomsButton = () => import('@/components/AtomsButton.vue')
export default createComponent({
components: {
AtomsButton
},
setup(props: {}, ctx: SetupContext) {
return (
//
)
}
})
import Vue from 'vue'
export default Vue.extend({
methods: {
increment() {
//
},
decrement() {
//
}
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
const increment = () => {
//
}
const decrement = () => {
//
}
setup(props: {}, ctx: SetupContext) {
return (
increment,
decrement
)
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
import { increment, decrement } from '@/compositions'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
return (
increment,
decrement
)
}
})
import Vue from 'vue'
export default Vue.extend({
methods: {
async fetchApi() {
await ..
}
}
})
import { createComponent, SetupContext, onMounted } from '@vue/composition-api'
export default createComponent({
const fetchApi = async () => {
await ..
}
onMounted(async () => {
await fetchApi()
})
setup(props: {}, ctx: SetupContext) {
return (
//
)
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
import { fetchApi } from '@/repositories'
export default createComponent({
setup(props: {}, ctx: SetupContext) {
return (
fetchApi
)
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
fetch({ route }) {
console.log(route.params)
},
setup(props: {}, ctx: SetupContext) {
return (
//
)
}
})
import { createComponent, SetupContext } from '@vue/composition-api'
export default createComponent({
fetch({ store }) {
store.dispatch('fetchAction')
},
setup(props: {}, ctx: SetupContext) {
return (
//
)
}
})
Under investigating.. 🤔
<template>
<component
:is="svg"
style="width: 16px;"
/>
</template>
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
props: {
name: {
type: String,
required: true
}
},
computed: {
svg() {
return () => import(`@/assets/img/${this.name}.svg`)
}
}
})
</script>
import { createComponent, SetupContext } from '@vue/composition-api'
type SvgProps = {
name: string
}
export default createComponent({
props: {
name: {
type: String,
required: true
}
},
setup(props: SvgProps, ctx: SetupContext) {
const svg = () => import(`@/assets/img/${props.name}.svg`)
return () => (
<component is={svg} style="width: 16px;" />
)
}
})
<template>
<component
:is="svg"
style="width: 16px;"
/>
</template>
<script lang="ts">
import { createComponent, SetupContext } from '@vue/composition-api'
type SvgProps = {
name: string
}
export default createComponent({
props: {
name: {
type: String,
required: true
}
},
setup(props: SvgProps, ctx: SetupContext) {
const svg = () => import(`@/assets/img/${props.name}.svg`)
return () => (
svg
)
}
})
</script>