import { storeToRefs } from 'pinia'
import { useStore } from '@/store/userStore'
export default {
setup() {
const userStore = useStore()
const { news, user } = storeToRefs(userStore)
return { userStore, news, user }
},
data() {
return {
postOpen: false,
postNews: null,
postTitle: null,
postContent: null,
createNews: false,
editNews: false,
loadedPosts: 5,
alert: null,
}
}
}
<template>
{{ news }} //Можно работать сразу в шаблоне
</template>
<template>
<div>Name - {{name}}</div>
<div>Name - {{age}}</div>
<div>Name - {{job}}</div>
<div class="w-25">
<div class="mb-3">
<input v-model="name" autosize type="text" placeholder="Please input"/>
</div>
<div class="mb-3">
<input v-model="age" autosize type="text" placeholder="Please input"/>
</div>
<div class="mb-3">
<input v-model="job" autosize type="text" placeholder="Please input"/>
</div>
<div class="mb-3">
<a href="#" @click.prevent="addPerson" class="btn btn-primary">Добавить</a>
</div>
</div>
</template>
<script setup>
import {ref} from 'vue'
const name = ref("")
const age = ref ("")
const job = ref("")
function addPerson() {
name.value = 'Alex'
age.value = '21'
job.value = 'Driver'
}
/*
function addPerson() {
axios.post('/api/anketa', {name: this.name, age: this.age, job: this.job})
.then(res =>{
name.value = res.data.name
age.value = res.data.age
job.value = res.data.job
console.log(res);
})
}
*/
</script>