1 Star 1 Fork 0

jmh65535 / eharts-vue-koa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

echartscreen

前端 vue + echart

vuecli 搭建项目

vue create echartscreen

安装 echart

npm install echarts --save

后端 koa

后端建议用 koa 脚手架 零成本速搭服务器 省去手动配置

koa 脚手架快速搭建服务器

npm i koa-generator -g
koa2 service
cd service
npm i

使用 koa-json

koa-json 把数据转换成 json 格式

const json = require('koa-json')
const Koa = require('koa')
const app = new Koa()

app.use(json())

app.use((ctx) => {
  ctx.body = { foo: 'bar' }
})

GET 请求后,输出如下内容:

{
  "foo": "bar"
}

使用 koa-bodyparser

var Koa = require('koa')
var bodyParser = require('koa-bodyparser')

var app = new Koa()
app.use(bodyParser())

app.use(async (ctx) => {
  // the parsed body will store in ctx.request.body
  // if nothing was parsed, body will be an empty object {}
  ctx.body = ctx.request.body
})

使用 koa-static

koa-static 本质就是读取静态文件,说白就是把异步读取文件 fs.readfile,包括图片等资源的步骤给封装了 所以我们可以方便的用来读取 json 文件 方便快速使用。

app.use(require('koa-static')(__dirname + '/public'))

跨域

//npm install --save koa2-cors

var Koa = require('koa')
var cors = require('koa2-cors')

var app = new Koa()
app.use(cors())

启动服务器

npm run start

在浏览器打开输入 http://127.0.0.1:3000/ 返回一个 html 页面 http://127.0.0.1:3000/string 返回一个字符串 http://127.0.0.1:3000/json 返回一个 json 数据

此时,可以在 public 目录放入存入 json 数据测试: http://127.0.0.1:3000/json/seller.json 目标达成

如何运行项目

  1. 下载项目包后者 git 克隆
// 2. 安装前端包 并启动
cd echartscreen
npm i
npm run serve
// 3. 安装服务器包 并启动
cd service
npm i
npm run start

项目展示

-->点击这里

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/hellojinjin/eharts-vue-koa.git
git@gitee.com:hellojinjin/eharts-vue-koa.git
hellojinjin
eharts-vue-koa
eharts-vue-koa
master

搜索帮助