安装node @vue/cli
新建前端项目
vue create frontend
了解 Bootstrap
最基本的模板
请确保你的页面遵循了最新的设计和开发标准。也就是说,使用 HTML5 doctype 并包含 viewport meta 标签以实现正确的响应式行为。把这些东西攒在一起,你的页面应该是这样的:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<metacharset="utf-8">
<metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css"integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"crossorigin="anonymous"></script>
</body>
</html>
了解 Font Awesome
新建 index.html
修改App.vue
搭建 Container 组件
Container.vue 基础框架
<template>
<div class="row">
<!-- 左右两屏 -->
<div class="col-md-4">
<!-- 左边是编辑部分 -->
<div class="form-group">
<input type="hidden" v-model="url">
</div>
<div class="form-group">
<input type="text" v-model="title" class="form-control" placeholder="标题">
</div>
<div class="form-group">
<textarea v-model="content" class="form-control" placeholder="内容"></textarea>
</div>
<div class="form-group">
<button class="btn btn-block btn-success" @click="saveBlog()">保存</button>
</div>
</div>
<div class="col-md-8">
<!-- 右边是博客内容表格部分 -->
<table class="table table-bordered table-hover">
<thead>
<th class="text-center">标题</th>
<th class="text-center">内容</th>
<th class="text-center">编辑</th>
<th class="text-center">删除</th>
</thead>
<tbody>
<tr v-for="blog in blogs" :key="blog.url">
<td>{{blog.title}}</td>
<td>{{blog.content}}</td>
<td>
<button class="btn btn-success" @click="editBlog(blog)">
<i class="fa fa-edit"></i>
</button>
</td>
<td>
<button class="btn btn-success" @click="deleteBlog(blog)">
<i class="fa fa-trash"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script>
export default {
name: 'Container',
props: {
},
data() {
return {
blogs: null,
url: '',
title: '',
content: ''
}
},
methods: {
getAll() {
},
saveBlog() {
},
editBlog() {
},
deleteBlog() {
}
},
mounted() {
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
添加 axios http 请求组件
npm install axios —save
导入 axios
获取文章、修改文章、保存文章
最终效果