Vue项目引入mockjs实现模拟数据开发

1.安装mockjs: npm install mockjs –save-dev
2.在main.js中引入:
require('./mock') // simulation data
3.在src/api下新建index.js用来对请求进行封装
import axios from 'axios'

// 封装axios的post请求
export function fetch(url, params) {
return new Promise((resolve, reject) => {
axios.post(url, params)
.then(response => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
} read more

Vue项目在Nginx下部署

前提:nginx可正常启动

1.切换目录到nginx配置目录下:cd /usr/local/nginx/conf
2.编辑nginx.conf文件:vi nginx.conf
3.主要进行service部分配置即可:
server
{
listen 8081;#监听端口,即配置好之后用来访问项目的端口
server_name localhost;#域名,没有就localhost吧,写ip也可以
root /app/vue/;#站点目录,该目录为vue项目编译后的静态资源放置目录,即build后dist下的文件copy到/app/vue/下
index index.html;
location ^~/vue { #过滤请求前缀为vue的进来这里,此处正则可以百度到
alias /app/vue;
try_files $uri $uri/ /vue/index.html;
}
location /api/ { #这里主要进行后端接口的代理转发,将包含api的请求全部转发到下面的连接,需开发环境就采用代理模式
proxy_pass http://110.120.130.140:0000/;

#Proxy Settings
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
access_log off;
}
4.保存修改并退出
5.切换到执行目录下:cd ../sbin
6.更新nginx引用的配置 ./nginx -s reload
7.如果无信息显示则说明执行成功,否则启动nginx,如显示配置的端口信息则说明更新成功: ./nginx read more

Vue组件之间的引用

以下介绍的引用方式只是多个引用方式中的一种

A引用B
<!-- A -->
<template>
  <test></test>
</template>

<script>
  import test from './Eu'

  export default {
    name: 'index',
    components: {
      test
    }
  }
</script>

<!-- B -->
<template>
  <h2>
    引用内容
  </h2>
</template>
<script>
  export default ({
 //此处name是否设置作用不大
    name: 'eu'
  })
</script>

Vue项目中引入ElementUI

前提:
1.该项目为idea中vue项目
2.已安装node和npm

步骤:

1.打开idea的Terminal(cmd或其它也可以)

2.移动到vue项目下

3.执行:npm install element-ui -S
打印日志为:
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ element-ui@2.3.9
added 67 packages and updated 1 package in 28.606s

4.可以到项目下的node_modules查看是否有element-ui文件夹

5.在main.js中添加
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)
6.在创建的组件中使用element-ui
<template>
  <div>
    <i class="el-icon-edit"></i>
  </div>
</template>