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.postId
if (postId) {
this.$axios({
url: '/post',
method: 'get',
params: {
postId
}
}).then(response => {
let data = response.data
this.title = data.title
this.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.status
let data = response.data
if (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)

vue - blog开发学习4的更多相关文章

  1. vue - blog开发学习5

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

  2. vue - blog开发学习2

    首页博客列表的开发 1.修改index.vue,使能够支持列表功能 <template> <div> <PostList v-for="(item,index) ...

  3. vue - blog开发学习1

    1.安装vue-cli vue intall -g vue-cli 2.创建项目 vue init webpack nblog 3.按提示要求配置项目 ? Project name nblog ? P ...

  4. vue - blog开发学习6

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

  5. vue - blog开发学习3

    1.添加less 和less-loader支持 npm install less less-loader --save-dev 2.新建main.less,将这个样式添加到home.vue中的cont ...

  6. vue - blog开发学7

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

  7. Vue学习笔记-Vue.js-2.X 学习(二)===>组件化开发

    ===重点重点开始 ========================== (三) 组件化开发 1.创建组件构造器: Vue.extends() 2.注册组件: Vue.component() 3.使用 ...

  8. 前端开发 Vue -1windows环境搭建Vue Node开发环境

    解决几个疑问: 想学习下vue.js,我理解的它是一个前端的框架,主要作用是对数据的处理,和juqery类似,所以不太理解为什么要在nodejs中npm install vue呢?在html文件中引入 ...

  9. Android开发学习路线图

    Android开发学习方法: Android是一个比较庞大的体系,从底层的Linux内核到上层的应用层,各部分的内容跨度也比较大.因此,一个好的学习方法对我们学习Android开发很重要. 在此建议, ...

随机推荐

  1. CSS样式表能否控制文字禁止选择,复制, 焦点

    div中禁止文字被选择 在做div的点击计数事件时,遇到一个小问题. 因为div里面有文字,所以当点击多次时,特别是鼠标点的比较快的时候,文字会被选中. 查了下,用css和javascript可以实现 ...

  2. Linux --忘记root密码/su: Authentication failure

    如果忘记了root用户的密码,或者su root的时候,提示:su: Authentication failure 那么,可以通过以下的方式来重新设置密码,而后,再尝试,那么就可以顺利su root了 ...

  3. Nginx的简单使用

    一.Nginx概述 Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务.它的特点是支持高并发:资源消耗少:可以做HTTP反向代 ...

  4. Delphi Win API 函数 MulDiv

    Delphi Win API 函数 MulDiv 原型:function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer; st ...

  5. Python基础教程(017)--执行Python的方式解释器运行及其他几种解释器简介

    前言 了解Python的解释器 内容 Python的解释器乳交有多个语言的实现 cPython---官方版本的C语言实现 Jython--可以运行在java平台 IronPython--可以运行在.n ...

  6. Delphi ListView的用法

    //增加 i := ListView1.Items.Count; with ListView1 do begin ListItem:=Items.Add; ListItem.Caption:= Int ...

  7. (转)k8s存储之NFS

    转:https://www.cnblogs.com/DaweiJ/articles/9131762.html 1 NFS介绍 NFS是Network File System的简写,即网络文件系统,NF ...

  8. PyQuery爬取历史天气信息

    1.准备工作: 网址:https://lishi.tianqi.com/xian/index.html 爬虫类库:PyQuery,requests 2.网页分析: 红线部分可更改为需要爬取的城市名,如 ...

  9. error C2065: “CString”: 未声明的标识符 ;fatal error C1189: #error : afxstr.h can only be used in MFC proje

    转自VC错误:http://www.vcerror.com/?p=1388 问题描述: error C2065: "CString": 未声明的标识符 fatal error C1 ...

  10. vue 页面添加水印 ts

    "use strict"; // tslint:disable-next-line: only-arrow-functions const setWatermark: (str: ...