vue实现个人博客
Vue實現個人博客
- 一、首頁
- 效果展示
- 標題的彩虹色展示
- 博客標題字母大寫以及博客預覽內容限制并在結尾加上“...”
- 分頁的實現
- 二、寫博客頁面
- 效果展示
- markdown編輯器
- 三、搜索功能
一、首頁
效果展示
在連數據庫前可用JSONplaceholder的數據接口用假數據來測試,先將整體樣式確定。確定好頁面后再連接數據庫的真數據。這里使用是數據庫是firebase(使用時要注意打開數據庫可寫和可讀)
標題的彩虹色展示
在main.js中全局自定義指令
Vue.directive('tit',{bind(el){el.style.color='#'+Math.random().toString(16).slice(2,8);} })定義完后在需要使用的標簽加上 v-tit 即可
博客標題字母大寫以及博客預覽內容限制并在結尾加上“...”
在main.js中全局定義過濾器
//標題大寫 Vue.filter('toUppercase',function(value){return value.toUpperCase() }) //內容限制 Vue.filter('snippet',function(value){return value.slice(0,100)+"..." })分頁的實現
頁面創建時,在生命周期函數created()中獲取數據庫數據并且分頁。這里的分頁樣式是引用的elementUI中的分頁組件。分頁在主要思路如下:
(參考自https://blog.csdn.net/illusion_melody/article/details/82714793)
二、寫博客頁面
效果展示
markdown編輯器
1、安裝
npm install mavon-editor --save
2、全局引入
import Vue from 'vue' import mavonEditor from 'mavon-editor' import 'mavon-editor/dist/css/index.css' // use Vue.use(mavonEditor)3、使用
<!-- :ishljs="true" 代碼高亮 --> <mavon-editor v-model='blog.preview' :ishljs="true" @change='updateDoc'></mavon-editor> updateDoc(value, render) {// render 為 markdown 解析后的結果this.blog.content = render;}4、添加博客時加上當時的日期,并且格式化
在main.js中全局定義函數獲取當時的時期并且格式化
三、搜索功能
可根據博文的標題和發布日期搜索
首頁點擊搜索按鈕觸發
搜索頁面綁定計算屬性:要展示的博客在filteredBlogs()返回的數組中遍歷
computed:{filteredBlogs(){var fb=[];if(this.selectTime!=''){for(let i=0;i<this.blogs.length;i++){if(this.blogs[i].time==this.selectTime){fb.push(this.blogs[i])}else{continue}}}else{fb=this.blogs}return fb.filter((blog)=>{return blog.title.match(this.search)})}}編輯頁面和詳細博客的頁面大致和以上相同
具體代碼:
【 gitee 】:https://gitee.com/chenyjoe/vue-blog
【github】:https://github.com/chenyjoe/vue-blog
總結
- 上一篇: 论python在金融行业的重要性_论金融
- 下一篇: python实现大富翁_Python3