• vue-cli 2.x 搭建项目


    一、vue-cli优势

    1.成熟的vue项目架构设计

    2.本地测试服务器

    3.集成打包上线方案

    二、系统要求

    1.node.js

    2. Git

    3.node命令行终端

    三、安装

    1.安装vue-cli

    npm install vue-cli -g

    2.初始化项目

    vue init webpack myproject

    3.安装项目依赖

    npm install

    4. 在localhost启动测试服务器  npm run dev

    生成上线目录 npm run build

    四、 安装vue-router

    cnpm install vue-router --save (保存配置)

    五、 安装vuex (状态管理)

    cnpm install vuex --save

    六、 安装 vue-resource

    npm install vue-resource

    Vue.use(VueResource)

    在<script>中,created(生命周期): function(){

    this.$http.get('请求地址').then(function(data){},function(err){})

    this.$http.post('请求地址',{‘userid':123}(参数)).then(function(data){},function(err){})

    }

    then前面的部分构成了一个promise对象,所以可以调用then方法。

    七、安装 json-server

    cnpm install -g json-server 

    在命令行中, json-server --watch  db.json --port 3004

    接着,访问http://localhost:3004即可

  • 相关阅读:
    100-days: twenty-four
    100-days: twenty-three
    100-days: twenty-two
    100-days: twenty-one
    100-days: twenty
    [NOI 2016]循环之美
    [NOI 2015]寿司晚宴
    [BZOJ 2655]calc
    [Codeforces 888G]Xor-MST
    [BZOJ 2839]集合计数
  • 原文地址:https://www.cnblogs.com/ceceliahappycoding/p/10397392.html
Copyright © 2020-2023  润新知