| app.js 后端入口 | index.html 入口页面 | .babelrc babel配置 | .gitignore git配置 | package.json | webpack.config.js webpack配置 | |-dist vue打包生成的文件 | |-node_modules 模块 | |-server 后端 | check.js | db.js 数据库 __| router.js 路由 | |-src 前端 |-assets 静态资源 |-components 组件 | App.vue | main.js
devServer: {
historyApiFallback: true,
noInfo: true,
//让前后端http请求都转到node的3000端口,而不是前端的8080端口
proxy: {
'/': {
target: 'http://localhost:3000/'
}
}
}
<!--App.vue--> <template> <div id="app"> <div class="black_line"></div> <div id="main"> <router-view name="sidebar"></router-view> <router-view></router-view> </div> </div> </template>
// main.js
const router = new VueRouter({
routes: [
{path: '/', components: {default: article, sidebar: sidebar}},
{path: '/article', components: {default: article, sidebar: sidebar}},
{path: '/about', components: {default: about, sidebar: sidebar}},
{path: '/articleDetail/:id', components: {default: articleDetail, sidebar: sidebar}},
{path: '/admin/articleList', components: {default: articleList, sidebar: sidebar}},
{path: '/admin/articleEdit', component: articleEdit},
{path: '/admin/articleEdit/:id', component: articleEdit},
{path: '/admin/signin', component: signin}
]
})
// main.js
// 按需引用element
import { Button, Message, MessageBox, Notification, Popover, Tag, Input } from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
const components = [Button, Message, MessageBox, Notification, Popover, Tag, Input]
components.forEach((item) => {
Vue.component(item.name, item)
})
const MsgBox = MessageBox
Vue.prototype.$msgbox = MsgBox
Vue.prototype.$alert = MsgBox.alert
Vue.prototype.$confirm = MsgBox.confirm
Vue.prototype.$prompt = MsgBox.prompt
Vue.prototype.$message = Message
Vue.prototype.$notify = Notification
// GET /someUrl
this.$http.get('/someUrl').then(response => {
// success callback
}, response => {
// error callback
});
this.$http.get('/api/articleDetail/' + id).then(
response => this.article = response.body,
response => console.log(response)
)
// router.js
router.get('/api/articleDetail/:id', function (req, res) {
db.Article.findOne({ _id: req.params.id }, function (err, docs) {
if (err) {
console.error(err)
return
}
res.send(docs)
})
})
// 新建文章
// 即将被储存的数据 obj
let obj = {
title: this.title,
date: this.date,
content: this.content,
gist: this.gist,
labels: this.labels
}
this.$http.post('/api/admin/saveArticle', {
articleInformation: obj
}).then(
response => {
self.$message({
message: '发表文章成功',
type: 'success'
})
// 保存成功后跳转至文章列表页
self.refreshArticleList()
},
response => console.log(response)
)
// router.js
// 文章保存
router.post('/api/admin/saveArticle', function (req, res) {
new db.Article(req.body.articleInformation).save(function (err) {
if (err) {
res.status(500).send()
return
}
res.send()
})
})
const express = require('express')
const fs = require('fs')
const path = require('path')
const bodyParse = require('body-parser')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const router = require('./server/router')
const app = express()
const resolve = file => path.resolve(__dirname, file)
app.use('/dist', express.static(resolve('./dist')))
app.use(bodyParse.json())
app.use(bodyParse.urlencoded({ extended: true }))
app.use(router)
// session
app.set('trust proxy', 1) // trust first proxy
app.use(session({
secret: 'blog',
resave: false,
saveUninitialized: true,
cookie: {
secure: true,
maxAge: 2592000000
},
store: new MongoStore({
url: 'mongodb://localhost:27017/blog'
})
}))
app.get('*', function (req, res) {
let html = fs.readFileSync(resolve('./' + 'index.html'), 'utf-8')
res.send(html)
})
app.listen(3000, function () {
console.log('访问地址为 localhost:3000')
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有