<template>
<p>{{ data }}</p>
</template>
<script setup>
import { computed } from 'vue'
import { useStore } from 'vuex'
const store = useStore()
const data = computed(() => store.state.user.data)
store.dispatch('user/get', userId)
</script>
const state = {
data: []
}
const getters = {}
const actions = {
async get ({commit}) {
try {
// Запрос к апи
commit('setUser', result)
} catch (error) {
throw error
}
}
}
const mutations = {
setUser (state, payload) {
state.status = 'success'
state.data = payload
}
}
export default {
namespaced: true,
state,
getters,
actions,
mutations
}
<template>
<div class="home">
<div class="container">
<div class="row">
<div class="col-md-4" v-for="dice in dices" :key="dice.diceId">
<div class="card mb-4 box-shadow">
<img :src="dice.diceImage" class="card-img-top" @click="generateNumber(dice.diceNumber)">
</div>
</div>
</div>
</div>
<div>Random Number: <strong style="color:red">{{ number }}</strong></div>
</div>
</template>
<script>
export default {
name: 'Home',
data () {
return {
number: null,
dices: [
{
diceId: 1,
diceNumber: 20,
diceImage: 'https://game-icons.net/icons/ffffff/000000/1x1/delapouite/dice-twenty-faces-twenty.svg'
},
{
diceId: 2,
diceNumber: 12,
diceImage: 'https://game-icons.net/icons/ffffff/000000/1x1/skoll/d12.svg'
},
{
diceId: 3,
diceNumber: 10,
diceImage: 'https://game-icons.net/icons/ffffff/000000/1x1/skoll/d10.svg'
},
{
diceId: 4,
diceNumber: 8,
diceImage: 'https://game-icons.net/icons/ffffff/000000/1x1/delapouite/dice-eight-faces-eight.svg'
},
{
diceId: 5,
diceNumber: 6,
diceImage: 'https://game-icons.net/icons/ffffff/000000/1x1/delapouite/perspective-dice-six.svg'
},
{
diceId: 6,
diceNumber: 4,
diceImage: 'https://game-icons.net/icons/ffffff/000000/1x1/skoll/d4.svg'
}
]
}
},
methods: {
generateNumber (diceNumber) {
const max = Number(diceNumber)
const min = +1
const randomNumber = Math.floor(Math.random() * (max - min + 1) + min)
this.number = randomNumber
}
}
}
</script>
<style scoped>
img {
width: 40px;
height: 40px;
}
</style>
<template>
<component-first data="{ "key": "data" }"></component-first>
</template>
<<script>
export default {
components: {
ComponentFirst
}
}
</script>
<template>
<p>{{ data }}</p>
</template>
<<script>
export default {
props: {
data: Array
},
setup (props) {
// work
}
}
</script>
<template>
<button v-on:click="read()">Read More</button>
<div v-show="isRead">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</template>
<<script>
import { ref } from 'vue'
export default {
setup () {
const isRead = ref(false)
function read () {
this.isRead = true
}
return {
isRead,
read
}
}
}
</script>
import { createApp } from 'vue'
import router from '../router'
import store from '../store'
createApp(App).use(router).use(store).mount('#app'