vue - blog开发学习4

1、新建页面的修改,集成富文本编辑 edit-post.vue(新建和修改都用该组件)

<template><div class="editor"><span class="h5 text-left">标题</span><Input v-model="title" size="large" placeholder="请输入标题~~~"/><span class="h5 text-left">内容</span><TinymceEditor ref="editor" v-model="content" :disabled="disabled" @onClick="onClick"></TinymceEditor><Button @click="submitPost">发布</Button><Button type="dashed" @click="submitPost">保存草稿</Button><Button type="warning" @click="clear">重置</Button></div>
</template><script>import TinymceEditor from '@/components/tinymce-editor'export default {name: "EidtPost",components: {TinymceEditor},data() {return {title: '',content: '',disabled: false}},mounted() {let postId = this.$route.params.postIdif (postId) {this.$axios({url: '/post',method: 'get',params: {postId}}).then(response => {let data = response.datathis.title = data.titlethis.content = data.content}).catch(error => {alert('出错了')})}},methods: {// 鼠标单击的事件(editor)
      onClick(e, editor) {// console.log('Element clicked')// console.log(e)// console.log(editor)
      },// 清空内容
      clear() {this.$refs.editor.clear()this.title = ''this.content = ''},submitPost() {this.$axios({url: '/createPost',method: 'post',data: {title: this.title,content: this.content}}).then(response => {let status = response.statuslet data = response.dataif (status === 200 && data.status === 1) {this.$Notice.success({title: '成功',desc: ''})this.$router.push({name: 'Index'})} else {this.$Notice.error({title: '出错',desc: data.msg})}}).catch(error => {alert("出错了")})}}}
</script><style scoped>.editor {padding: 20px;height: 100%;margin-left: 10%;margin-right: 10%;text-align: left;}</style>

2、路由配置

{path: '/editPost',name: 'EidtPost',component: EidtPost
},

3、模拟数据

const create = () => {return {status: 1,msg: '成功'}
}Mock.mock('/createPost', 'post', create)

4、编辑页面的修改(和index.vue组件类似,基本上就是复制了一份)

<template><div><Scroll :on-reach-bottom="handleReachBottom" :distance-to-edge="scroll" :height="height"><EditPostList v-for="(item,index) in postList" :postId="item.postId" :postTitle="item.title":content="item.content":postCount="postCount":key="index"></EditPostList></Scroll></div>
</template><script>import EditPostList from '@/components/edit-post-list'export default {name: "EditList",components: {EditPostList},data() {return {height: document.body.clientHeight * 0.85,scroll: [20, 20],postList: [],postCount: 100}},created() {this.getPostList()},methods: {handleReachBottom() {this.getPostList()},getPostList() {this.$axios({url: '/api/posts',method: 'get'}).then(response => {this.postList = [...this.postList, ...response.data.posts]})}}}
</script><style scoped></style>

5、修改edit-post-list.vue组件

<template><div style="background: #eee;padding: 1px; margin-left: 10%;margin-right: 10%"><router-link tag="div" :to="{name:'Post',params:{postId}}"><Card :bordered="false" class="text-left"><div><p slot="title" style="margin-bottom: 0px;height: 25px"><Avatar icon="ios-paper-outline" size="small"/>&nbsp;&nbsp;<b> {{postTitle}}</b></p><p>{{content}}</p><div><p>2019-05-29</p><Button style="position: absolute;right: 20px;bottom: 20px" size="small" @click.stop="editPost(postId)">修改</Button></div></div></Card></router-link></div>
</template><script>export default {name: "EditPostList",props: {postId: {type: String,default: ''},postTitle: {type: String,default: ''},content: {type: String,default: ''},postCount: {type: Number,default: 0}},methods: {editPost(postId){this.$router.push({name:'EidtPost',params:{postId}})}}}
</script><style scoped>div p {margin-bottom: 0px;height: 25px}
</style>

6、模拟的数据

//引入mockjs
const Mock = require('mockjs')
// 获取mock.Random对象
const Random = Mock.Random//mock数据
const postList = () => {let posts = []for (let i = 0; i < 10; i++) {let post = {postId: Random.integer(1, 1000) + '',title: Random.csentence(5, 15),content: Random.csentence(50, 100)}posts.push(post)}return {posts: posts}
}
Mock.mock('/api/posts', 'get', postList)

posted @ 2019-06-08 14:51 巡山小妖N 阅读(...) 评论(...) 编辑 收藏

vue - blog开发学习4相关推荐

  1. vue - blog开发学习6

    vue - blog开发学习6 1.问题,如下图,使用iviewui中的card导致页面不能出现滚动条(不太会弄,在网上查了一个vue组件vuescroll,因此使用这个做滚动条) 2.安装vuesc ...

  2. vue - blog开发学习5

    vue - blog开发学习5 基本功能和后台联调 1.首页的所有博客 因为是前后台都是本地开发,所以前端vue需要设置proxy:修改/config/index.js中的这个proxyTable p ...

  3. vue - blog开发学习3

    vue - blog开发学习3 1.添加less 和less-loader支持 npm install less less-loader --save-dev 2.新建main.less,将这个样式添 ...

  4. vue - blog开发学习2

    vue - blog开发学习2 首页博客列表的开发 1.修改index.vue,使能够支持列表功能 <template><div><PostList v-for=&quo ...

  5. vue - blog开发学习1

    vue - blog开发学习1 1.安装vue-cli vue intall -g vue-cli 2.创建项目 vue init webpack nblog 3.按提示要求配置项目 ? Projec ...

  6. vue - blog开发学7

    vue - blog开发学7 将基本的项目部署到linux上(前后台只是实现了基本的功能,本次只是记录一些基本的开发流程,完善,等后续) 1.linux环境准备(我用的是阿里云服务器) ①jre.my ...

  7. 【Vue前端开发学习】第2章,Vue项目目录结构

    文章目录 前言 一.新增router文件夹及其配置方法 二.新增store文件夹及其配置方法 三.index.html.App.vue.main.js三者之间的联系 前言   上一章节,通过Pycha ...

  8. 五、Vue模块化开发学习笔记——JavaScript原始功能、匿名函数的解决方案、使用模块作为出口、CommonJS、ES6 export和import的使用

    一.JavaScript原始功能 -在网页开发的早期,js制作作为一种脚本语言,做一些简单的表单验证或动画实现等,那个时候代码还是很少的. 那个时候的代码是怎么写的呢? 直接将代码写在<scri ...

  9. Vue 官网学习笔记

    VUE介绍 vue git 地址:https://github.com/vuejs/vue/projects Vue 官网教程地址:https://cn.vuejs.org/v2/guide/inst ...

最新文章

  1. BZOJ 4212: 神牛的养成计划
  2. 怎么调节电机启动值_发电机组的几个使用规范技巧
  3. todo在此放置对话框控件_MFC界面开发进入BCGControlBar v30.5时代,Gantt Chart控件升级...
  4. python搭建selenium_自动化测试之路3-selenium3+python3环境搭建
  5. linux内核mtd分区,linux-kernel – 在运行时调整MTD分区大小
  6. TPL Dataflow .Net 数据流组件,了解一下?
  7. SQL:如何用一个sql统计出全校男生个数、女生个数以及总人数
  8. 微服务“新秀”之Service Mesh
  9. Docker使用小结(一)Docker镜像以及Docker容器
  10. 【定位问题】基于matlab GUI RSSI无线定位【含Matlab源码 1054期】
  11. 抓取csdn上的各类别的文章 (制作csdn app 二)
  12. 汉仪欧楷字体获2016中国设计红星奖银奖
  13. VC2005运行库文件
  14. 2023苏州大学计算机考研信息汇总
  15. 智能语言处理之依存树计算句子结构相似度计算
  16. 《改变心理学的40项研究》第二章 知觉与意识
  17. 5G+智能电网应用项目开建,将带来何种“活力”?
  18. 浪潮刀片服务器型号,浪潮刀片服务器.pdf
  19. sougou linux 无法切换中英文,Ubuntu 16.04安装GoLand后不能切换到搜狗输入法
  20. 2021 数据挖掘与大数据分析复习笔记 电子科技大学《数据挖掘与大数据分析期末》课程期末高分指南

热门文章

  1. python实验收获_python实验课代码心得
  2. html不同平台,基于H5端自定义平台怎么使用和H5端不一样的index.html?
  3. java怎么缓存行填充_为什么java的Exchanger.Slot缓存行填充像这样?
  4. oracle 求时间差年,Oracle计算时间差常用函数
  5. 阶乘之和计算_利用MULTINOMIAL函数计算参数和的阶乘与各参数阶乘乘积的比 值
  6. vue el-upload上传组件限制文件类型:accept属性
  7. icu入院宣教流程图_ICU患者及家属的健康教育PPT.ppt
  8. pandas库基础学习
  9. java akka_Akka系列(九):Akka分布式之Akka Remote
  10. 计算机组成原lta,计算机组成原理实验三运算器