我目前正在为工作学习 VueJS,我正在尝试构建一个 CRUD 应用程序,该应用程序显示从 API 到 a 的项目<v-data-table>
,我想使用<v-dialog>
.
这是我的主屏幕:
<template>
<v-app>
<v-main>
<div>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
single-line
hide-details
label="search">
</v-text-field>
<v-data-table
:items="movies"
:headers="headers"
:search="search"
>
<template v-slot:[`item.actions`]>
<edit-movie></edit-movie>
<delete-movie></delete-movie>
<details-movie></details-movie>
</template>
</v-data-table>
</div>
</v-main>
</v-app>
</template>
<script>
import {mapState} from 'vuex';
import DeleteMovie from './components/deleteMovie.vue';
import DetailsMovie from './components/detailsMovie.vue';
import EditMovie from './components/editMovie.vue';
export default {
name: 'App',
components: {
EditMovie,
DeleteMovie,
DetailsMovie
},
mounted(){
this.$store.dispatch('getMovies');
},
data: () => ({
search: ''
}),
computed: {
headers() {
return [
{text: "Title", value: "title"},
{text: "Overview", value: "overview"},
{text: "Votes", value:"vote_average"},
{text: 'Actions', value: 'actions', sortable: false },
{text: '', value: 'details'},
]
},
...mapState({
movies:state => state.movies
})
},
}
</script>
我这样调用 API:
export default new Vuex.Store({
state: {
movies: [],
},
mutations: {
async getMovies(state){
let response = await axios.get(`https://api.themoviedb.org/3/movie/now_playing?api_key=${public_key}&language=en-US`)
.then((result) => {
result.data.results.forEach(item => {
console.log(item)
state.movies.push(item)
});
})
.catch((error) => {
console.log(error)
})
}
},
actions: {
getMovies: context => {
context.commit('getMovies')
},
},
})
现在,我主要关心的是如何调用单个项目并在此对话框中显示所有详细信息:(它必须在不同的组件中)
<template>
<v-dialog>
<template v-slot:activator="{ on, attrs }">
<v-btn
small
class="mr-2"
v-on="on"
v-bind="attrs"
>
Read More
</v-btn>
</template>
<v-card>
<v-card-text>
{{THIS IS WHERE IT SHOULD BE DISPLAYED}}
</v-card-text>
</v-card>
</v-dialog>
</template>
<script>
export default {
data: () => ({
}),
}
</script>
我也不知道如何从不同组件的对话框中编辑/删除项目。
无论如何,提前感谢您的帮助