<template>
<div id="single-blog">
<h1>{{blog.title}}</h1>
<article>{{blog.content}}</article>
<p>作者:{{blog.author}}</p>
<p>分类:{{blog.categories}}</p>
<button @click="deleteSingleBlog()">删除</button>
<router-link :to="'/edit/'+id">编辑</router-link>
</div>
</template>
<script>
export default{
name:"single-blog",
data(){
return {
//拿到路径后的参数
id:this.$route.params.id,
blog:{}
}
},
created(){
const query = Bmob.Query('blog');
query.get(this.id).then(res => {
this.blog = res;
}).catch(err => {
console.log(err)
})
},
methods:{
deleteSingleBlog(){
const query = Bmob.Query('blog');
query.destroy(this.id).then(res => {
this.$router.push({path:'/'})
}).catch(err => {
console.log(err)
});
}
}
}
</script>
<style>
#single-blog{
max-width:960px;
margin:0 auto;
padding: 20px;
background:#eee;
border:1px dotted #aaa;
}
</style>