1.初始化vue项目

1.1环境初始化

1.安装node。官网直达

2.安装淘宝npm镜像提高下载速度。 npm install -g cnpm --registry=https://registry.npm.taobao.org

3.安装vue脚手架vue-cli。 npm install --global vue-cli

1.2创建项目

1.创建一个基于 webpack 模板的新项目my-blog。 vue init webpack my-blog

2.创建过程中会提示是否需要vue-router、eslint、unit tests等,全部输入no。

1.3安装依赖,启动项目

1.切换到项目目录 cd my-blog

2.安装依赖 cnpm install

3.启动运行 cnpm run dev

4.如果浏览器没有自动启动运行,请查看命令行输出的打印信息,把最后的网址拷贝到浏览器地址栏即可。我这里是                       http://localhost:8080

2.实现添加博客页面

1.效果图
2.在components下新建一个AddBlog.vue文件。
<template><div id="add-blog"><h2>添加博客</h2><form v-if="!submmited"><label>博客标题</label><input type="text" v-model="blog.title" required /><label>博客内容</label><textarea v-model="blog.content"></textarea>  <!-- 博客分类 --><div id="checkboxes"><span>Vue.js</span><input type="checkbox" value="Vue.js" v-model="blog.categories"><span>Node.js</span><input type="checkbox" value="Node.js" v-model="blog.categories"><span>React.js</span><input type="checkbox" value="React.js" v-model="blog.categories"><span>Angular4</span><input type="checkbox" value="Angular4" v-model="blog.categories"></div><!-- 作者 --><label>作者:</label><select v-model="blog.author"><option v-for="author in authors">{{author}}</option></select><button v-on:click.prevent="post">添加博客</button></form> <!-- 提示信息 --><div v-if="submmited"><h3>您的博客发布成功!</h3></div><!-- 博客总览 --><div id="preview"><h3>博客总览</h3><p>博客标题: {{blog.title}}</p><p>博客内容:</p><p>{{blog.content}}</p><p>博客分类:</p><ul><li v-for="category in blog.categories">{{category}}</li></ul><p>作者: {{blog.author}}</p></div></div>
</template><script>
export default {name: 'add-blog',data () {return {blog:{title:"",content:"",categories:[],author:""},authors:["Hemiah","Henry","Bucky"],// 是否提交submmited:false}
},
// npm install vue-resource --save
methods:{post:function(){this.$http.post("https://......awfuoz.wilddogio.com/posts.json",this.blog).then(function(data){console.log(data);this.submmited = true;}) }
}
}
</script><!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#add-blog *{box-sizing: border-box;
}#add-blog{margin: 20px auto;max-width: 600px;
}label{display: block;margin:20px;
}input[type="text"],textarea,select{display: block;width: 100%;padding: 8px;
}textarea{height: 200px;
}#checkboxes input{display: inline-block;margin-right: 10px;
}button{display: block;margin: 20px auto;background: crimson;color: #fff;border: 0;padding: 14px;border-radius: 4px;font-size: 18px;cursor: pointer;
}#preview{padding: 10px 20px;border: 1px dotted #ccc;margin: 30px 0;
}h3{margin-top: 10px;
}
</style>

3.其他

1.安装vue-resource。cnpm install vue-resource --save
2.在main.js中引入vue-resource。
import VueResource from 'vue-resource'
Vue.use(VueResource)
3.将数据提交到野狗云,存储数据。
4.注意这里需要将你数据库的读写权限都设为true
5.远程数据库中的数据

3.博客总览页面

1.效果图
2.在components下新建一个ShowBlogs.vue文件。
<template><!-- 传入的参数 --><div v-theme:column="'narrow'" id="show-blogs"><h1>博客总览</h1><input type="text" v-model="search" placeholder="搜索"><div v-for="blog in filteredBlogs" class="single-blog"> <router-link v-bind:to="'/blog/' + blog.id"><h2 v-rainbow>{{blog.title | to-uppercase}}</h2></router-link><article>{{blog.content | snippet}}</article></div></div>
</template><script>export default {name: 'show-blogs',data(){return {blogs:[],search:""}},//或者是 ./../static/post.json 注:资源文件只能放在static目录下created(){this.$http.get('https://......awfuoz.wilddogio.com/posts.json').then(function(data){return data.json()//Response }).then(function(data){ var blogsArray = [];//将对象放到数组里面去for(let key in data){console.log(data);console.log(data[key]);data[key].id = key;blogsArray.push(data[key]);}this.blogs = blogsArray;})},//computed:{filteredBlogs:function(){return this.blogs.filter((blog) =>{//blog每一篇文章return blog.title.match(this.search)})}},//过滤器filters:{"to-uppercase":function(value){return value.toUpperCase();},"snippet":function(value){return value.slice(0,100) + "...";}
},
//自定义指令
directives:{'rainbow':{bind(el,binding,vnode){el.style.color = "#" + Math.random().toString(16).slice(2,8);}},'theme':{bind(el,binding,vnode){if(binding.value =="wide"){el.style.maxWidth = "1260px";}else if (binding.value == 'narrow') {el.style.maxWidth = "560px";}if (binding.arg == 'column') {el.style.background = "#6677cc";el.style.padding = '20px';} }
}
}
}
</script><style>
#show-blogs{max-width: 800px;margin: 0 auto;
}.single-blog{padding: 20px;margin: 20px 0;box-sizing: border-box;background: #eee;border: 1px dotted #aaa;
}#show-blogs a{color: #444;text-decoration: none;
}input[type="text"]{padding: 8px;width: 100%;box-sizing: border-box;
}</style>

3.博客详情页

1.效果图
2.在components下新建一个SingleBlog.vue文件。
<template><div id="single-blog"><h1>{{blog.title}}</h1><article>{{blog.content}}</article><p>作者: {{blog.author}}</p><p>分类:</p><ul><li v-for="category in blog.categories">{{category}}</li></ul></div>
</template><script>
export default{name:"single-blog",data(){return{id:this.$route.params.id,blog:{}}},created(){this.$http.get('https://......awfuoz.wilddogio.com/posts/' + this.id + ".json").then(function(data){return data.json();}).then(function(data){this.blog = data;})}
}
</script>
<style>
ul,li{list-style: none;
}
#single-blog{max-width: 960px;margin: 0 auto;padding: 20px;background: #eee;border: 1px dotted #aaa;
}
</style>

3.其他

1.通过this.$route.params.id获取传过来的值

4.头部页面

1.效果图
2.在components下新建一个BlogHeader.vue文件。
<template><nav><ul><li><router-link to="/" exact>博客</router-link><router-link to="/add" exact>写博客</router-link></li></ul></nav>
</template><script>export default{name:"blog-header"}
</script><style scoped>
ul{list-style-type: none;text-align: center;margin: 0;
}
li{display: inline-block;margin: 0 10px;
}a{color: #fff;text-decoration: none;padding: 12px;border-radius: 5px;
}
nav{background: crimson;padding: 30px 0;margin-bottom: 40px;
}.router-link-active{background: rgba(255,255,255,0.8);color: #444;
}</style>

3.其他

1.安装vue-router。 cnpm install vue-router --save
2.在main.js中引入vue-router。
import VueRouter from 'vue-router'
Vue.use(VueRouter)

5.路由配置

1.在src下新建一个routes.js文件。
import ShowBlogs from './components/ShowBlogs.vue'
import AddBlog from './components/AddBlog.vue'
import SingleBlog from './components/SingleBlog.vue'export default[{path:"/",component:ShowBlogs},{path:"/add",component:AddBlog},{path:"/blog/:id",component:SingleBlog},
]

2.在main.js中

import Routes from './routes'
// 创建路由
     const router = new VueRouter({
   routes: Routes,
   mode:"history"
     })
new Vue({
 router:router,
 el: '#app',
 template: '<App/>',
 components: { App }
     })

6.首页

1.效果图
2.App.vue
<template><div id="app"> <blog-header></blog-header><router-view></router-view> </div>
</template><script>
import BlogHeader from './components/BlogHeader'export default {name: 'app',components: {BlogHeader}
}
</script><style>
#app {font-family: 'Avenir', Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-align: center;color: #2c3e50;margin-top: 60px;
}
</style>

7.打包上传到服务器

1.将项目进行打包。cnpm run build
2.自动生成dist文件
3.只需要将static和index.html上传到服务器即可

GithHub

Vue--搭建个人博客相关推荐

  1. 搭建个人博客网站 -- vue初学者学习总结

    搭建个人博客网站 – vue技术学习 开源代码:个性化个人博客系统 参考项目:风丶宇的个人博客 一.项目概述 项目主要是基于SpringBoot + Vue 开发的前后端分离博客,本文主要涉及项目前端 ...

  2. 基于springboot + vue 的个人博客搭建过程(上线)

    承接上文: 基于springboot + vue 的个人博客搭建过程(续) 目录 1. 搭建环境 1. 安装docker 2. 拉取并运行 2.1 拉取服务 2.2 部署运行mysql 2.3 部署运 ...

  3. 基于springboot + vue 的个人博客搭建过程(续)

    承接上文:基于springboot + vue 的个人博客搭建过程 目录 1. 评论列表 1.1 接口说明 1.2 controller 1.3 service 1.4 mapper 1.5 实体类 ...

  4. Vue + VueRouter + Vuex + Axios 抓取 GitHub 上的 Issues 来搭建个人博客站点

    项目背景 刚接触 GitHub 的时候就开始在仓库 bingoogolapple.github.io 里创建 Issues 来记录学习笔记,那时候我还不知道有 GitHub Pages,后来了解到了可 ...

  5. Vue实战狗尾草博客后台管理系统

    Vue实战狗尾草博客后台管理系统第一章 这里准备采用的技术栈为:vue全家桶+element-ui 这里因为是后台管理系统,没有做SSR的必要.所以这里就采用前后端分离来昨晚这个项目~ 项目搭建 vu ...

  6. hexo+git+github+域名搭建个人博客提示404_不用花一分线,松哥手把手教你上线个人博客...

    有不少小伙伴私信松哥,打听松哥的博客是怎么做的,其实这个我之前和大家聊过,今天就再来说一说. 我记得是 2015 年 4 月 15 在CSDN上发表了我的第一篇博客,是一个学习笔记,从那之后开启了我博 ...

  7. 手把手教你使用 VuePress 搭建个人博客

    手把手教你使用 VuePress 搭建个人博客 有阅读障碍的同学,可以跳过第一至四节,下载我写好的工具包: git clone https://github.com/zhangyunchencc/vu ...

  8. python vue token_Haytham个人博客开发日志 -- Flask+Vue基于token的登录状态与路由管理...

    指路牌 符合一下关键词,这篇博客有可能会对你有帮助 不使用工厂函数的Flask应用 不使用蓝本的Flask应用 Flask跨域配置 基于Token的登录状态管理 Flask+Vue Vue路由拦截 A ...

  9. 使用vuepress搭建静态博客

    什么是vuePress vuePress是以vue驱动的主题系统的简约静态网站生成工具(拥有自己的默认主题). veuPress由vue,vue-router,webpack驱动的单页面应用,每个ma ...

  10. 手把手教你从0开始搭建个人博客,东半球最详细的保姆级博客搭建部署教程 | 程序员人手必备个人博客网站

    Hello 小伙伴们大家好,我是雷小帅! 想象一下你有一个技术博客,然后把网址写在了简历上,面试官点击鼠标打开了这个网站,然后被惊艳了,最后面试的结果你懂得-- 好了,今天的主题就是手把手教大家从零开 ...

最新文章

  1. 【控制】《现代控制理论》谢克明老师-第4章-控制系统的稳定性
  2. 一文读懂 K8s 持久化存储流程
  3. 用友u8服务器优化,用友U8v10.1运行速度慢的问题及解决方法
  4. html placehonlder属性,HTML input placeholder 属性
  5. canvas笔记-阴影的使用
  6. orm2 中文文档 2. 设置
  7. Texpad for Mac编辑器使用说明
  8. 计算机软件技术基础_「连载」信息技术基础题型归纳之计算机软件2
  9. java生成word带多级标题,word自动生成多级标题的方法
  10. Multisim使用入门教程
  11. stm32f030移植到stm32f072
  12. 硬盘容量统计神器WinDirStat
  13. 高通camera模块驱动指南资料介绍
  14. ntp版本导致时间同步不成功问题
  15. 第三章 图表辅助元素的定制
  16. 利用Docker 基于Uptime Kuma搭建服务器监控
  17. linux怎么看系统内存多大内存频率,Linux 查看 CPU 型号及内存频率及其它信息的命令...
  18. 迈卡名车茂品牌LOGO全新升级
  19. SpringCloud入门 —— SSO 单点登录
  20. IIS6.0功能及应用详解

热门文章

  1. codecademy SQL lesson2
  2. 《私募股权基金投资基础知识》---第五章
  3. JS逆向加密解密工具Crypto Magician、乐易助手、WT-JS 下载使用
  4. 正在构建的“大而全”的网络帝国 --- 腾讯
  5. mastercam9.1按alt键卡机,mastercam输入参数卡机需要win10输入法兼容性设置
  6. 相对定位、绝对定位、固定定位
  7. 两台计算机互相共享一个网络,两台电脑共用一个路由器上网,但两台电脑不能互相访问共享,怎样设置啊?两台电脑系统都XP的...
  8. 程序员史诗级必读书单吐血整理四个维度系列80+本书(珍藏版)
  9. 论《计算机网络技术》与素质教育
  10. 使用 backdoor 工具注入ShellCode