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. 2019-9-8-WPF-渲染原理

    title author date CreateTime categories WPF 渲染原理 lindexi 2019-9-8 10:40:0 +0800 2018-7-15 16:2:47 +0 ...

  2. 天启android5.1系统无法在非1650批次号的rk3288w芯片上启动

    天启android5.1系统无法在非1650批次号的rk3288w芯片上启动 挂掉log,说明在rtc初始化后挂掉 [ ) HIGH! ======== [ [ [ 1.420258] [WLAN_R ...

  3. C语言实现读取文件所有内容到字符串

    #include "stdio.h" #include "string" #include "stdlib.h" using namespa ...

  4. 初学Java 使用输入对话框

    import javax.swing.JOptionPane; public class ComputeLoanUsingInputDialog { public static void main(S ...

  5. pip命令一般使用

    pip类似RedHat里面的yum,安装Python包非常方便.本节详细介绍pip的安装.以及使用方法. 1.pip下载安装 1.1 pip下载   1 # wget "https://py ...

  6. HTML基础 块级元素和内联元素

    大多数 HTML 元素被定义为块级元素或内联元素. 块级元素包括:body  from  select  textarea  h1-h6 html table  button  hr  p  ol   ...

  7. pandas模块之读取文件

    首先我们来看一个文件 1 男 北京 刘一 我笑 #跳过此行,序号1 2 女 上海 刘珊 你笑 3 男 杭州 刘五 他笑 #跳过此行,序号四 4 女 重庆 刘六 不笑了 下面来分析内容,并使用参数 1 ...

  8. hdu 2665 Kth number (poj 2104 K-th Number) 划分树

    划分树的基本功能是,对一个给定的数组,求区间[l,r]内的第k大(小)数. 划分树的基本思想是分治,每次查询复杂度为O(log(n)),n是数组规模. 具体原理见http://baike.baidu. ...

  9. ubuntu下安装pyaudio

    首先安装依赖库,不安装依赖库会安装失败: sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocp ...

  10. c++ 预处理指令#define, #endif...

    常见的预处理指令有: # 空指令,无任何效果 # include 包含一个源代码文件 #define 定义宏 #undef 取消已定义的宏 #if 如果给定条件为真,则编译下面代码 #ifdef 如果 ...