第一个web项目实例总结1

1.环境准备

1.安装vue(已经安装过npm)
cnpm install vue
2.安装vue-cli:
cnpm install --global vue-cli
3.Web前端开发编辑工具WebStorm下载、安装及破解
激活破解:https://blog.csdn.net/voke_/article/details/76418116
4.git 基础框架代码下载
(如何快速搭建创建的基础框架 http://www.runoob.com/vue2/vue-install.html
5.打开项目,配置运行方式:

image.png

2.项目目录

image.png

1.目录中的各个文件作用如下:
build:项目构建代码
config:配置目录
node_modules:项目依赖模块,(具体的不是特别清楚)
src:开发目录,写的代码基本都在这个文件夹下面
assets:放图片
components: 放各种组件
pages:放我们的项目组件放在这里,其实可以放到components文件夹下
router:index.js配置路由信息
App.vue:项目入口文件
main.js:项目核心文件
package.json:配置文件文档

2.main.js、APP.vue代码、index.js代码:
main.js:

//引入Vue、ElementUI、element-ui/lib/theme-chalk/index.css、App、router、axios、../config/axios
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import axios from 'axios'
import '../config/axios'

Vue.use(ElementUI)

Vue.config.productionTip = false
/* eslint-disable no-new */
let vm = new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

Vue.use({
  vm
})
// Vue.prototype.axios=axios;
axios.defaults.headers = {
  'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}

实例化Vue:
通过var vm = new Vue({
// 选项
})
APP.vue代码:

<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

这里的id的值app就是main.js中el中的app。
index.js代码:

import Vue from 'vue'
import Router from 'vue-router'
import TestPage from '@/pages/TestPage'
import Group from '@/pages/Group'
import ServerList from '@/pages/ServerList'
import BusinessLine from '@/pages/BusinessLine'
import Login from '@/pages/Login'
import Main from '@/pages/Main'
import Interface from '@/pages/Interface'

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/',
      component: Main,
      children: [
        {
          path: '',
          name: 'Main',
          component: Group
        },
        {
          path: '/group',
          name: 'Group',
          component: Group
        },
        {
          path: '/test',
          name: 'TestPage',
          component: TestPage
        },
        {
          path: '/businessline',
          name: 'BusinessLine',
          component: BusinessLine
        },
        {
          path: '/serverlist',
          name: 'ServerList',
          component: ServerList
        },
        {
          path: '/interfaceinfos',
          name: 'Interface',
          component: Interface
        }
      ]
    }
  ]
})

@自动映射到src目录下
Vue.use(Router):全局使用vue-router
这里的路径就是浏览器访问的路径

3.BusinessLine.vue之移动功能

BusinessLine.vue文件包含三个部分:template、script、style
template:写html,定义元素
script:主要写各种方法,在template的定义的按钮上点击时会触发这个方法
style:这里可以定义元素格式

BusinessLine.vue中移动业务线功能:
移动业务线:将当前团队下的该业务线移动到其他团队中。
界面如下:


image.png

image.png

image.png

template部分:

 <span :name="businessline.id">
              <el-button-group style="float: right;padding: 2px 0;vertical-align:middle">
                <el-button size="small" type="warning" icon="el-icon-edit"
                           @click="editBusinessLine(businessline.id,businessline.name,0)"></el-button>
                <el-button size="small" type="warning" icon="el-icon-sold-out" @click="showDialog(businessline.id)"></el-button>
                <el-button size="small" type="warning" icon="el-icon-delete"
                           @click="deleteBusinessLine(businessline.id,businessline.name)"></el-button>
              </el-button-group>
              </span>

这是个button-group,第二个按钮是移动功能
这里用的是element的组件,参数size可以定义大小,type定义类型,icon是button的图标,@click定义点击这个按钮会调用的方法

<span :id="businessline.name">
                <el-dialog
                  title="移动业务线到其他团队"
                  :visible.sync="dialogVisible"
                  width="30%"
                  :before-close="handleClose">
                  <el-select  style="height:20px;width:330px;" v-model="value" placeholder="选择团队" @change="selectValue(value)">
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                     </el-select>
                  <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="moveBusiness(idTemp,value)">确 定</el-button>
                  </span>
                </el-dialog>
              </span>

这里主要用了element的对话框el-dialog组件和选择器el-select 组件
title:对话框的标题
:visible.sync:dialogVisible的值为false时不展示该对话框,为true时展示
width:占30%的宽度
:before-close:关闭前的回调,会暂停 Dialog 的关闭
value:选项的值
label:选项的标签
el-option:指每一个选项
v-model:值为当前被选中的el-option的 value 属性值
placeholder:占位符
加冒号的,说明后面的是一个变量或者表达式,没加冒号的后面就是对应的字符串字面量
@click定义点击确定时调用函数moveBusiness(idTemp,value)
script部分:

 data () {
    return {
      businessList: [],
      addBusinessResult: '',
      editBusinessResult: '',
      businessPageSize: '9',
      currentPage: 1,
      groupId: '',
      input10: '',
      groupToatal: '',
      groupList: '',
      options: [],
      groupName: '',
      dialogVisible: false,
      idTemp: '',
      value: '',
      loading2: true,
      getBusinessResult: ''
    }
  },

定义了options、dialogVisible、value、idTemp的初始值
点击页面的移动按钮会调用showDialog函数,把当前的businessId取出来存到idTemp中,this.dialogVisible = true将对话框设置为可见,然后获取团队的信息。

showDialog (businessId) {
      this.idTemp = businessId
      this.dialogVisible = true
      this.getGroups()
    }

调用接口获取团队信息,response.data.data列表的每一项的id和name值循环取出来,存入选择器options的value和label中。

getGroups () {
      let currentTime = new Date()
      axios({
        method: 'get',
        url: 'http://localhost:8082/interface/group/all' + '?timestamp=' + currentTime.getTime(),
        withCredentials: true,
        crossDomain: true
      }).then((response) => {
        console.log(response.data)
        this.groupList = response.data
        for (var myArray in this.groupList.data) {
          console.log(this.groupList.data[myArray])
          this.options.push({
            value: this.groupList.data[myArray].id,
            label: this.groupList.data[myArray].name
          })
        }
      }).catch(function (error) {
        console.log(error)
      })
    },

再点击确认的时候执行移动操作

moveBusiness (businessId, groupId) {
      let currentTime = new Date()
      axios({
        method: 'post',
        url: 'http://localhost:8082/interface/businessline/move/' + businessId + '/' + groupId + '?timestamp=' + currentTime.getTime(),
        withCredentials: true,
        crossDomain: true
      }).then((response) => {
        this.editBusinessResult = response.data
        switch (this.editBusinessResult.result) {
          case 'SUCCESS':
            this.$message({
              type: 'success',
              message: '移动业务线成功'
            })
            this.getData(this.groupId, this.currentPage)
            this.dialogVisible = false
            break
          default:
            this.$message.error('移动业务线失败')
            this.dialogVisible = false
        }
      }).catch(function (error) {
        console.log(error)
      })
    },

4.created和mounted

 created () {
    // 获取上个页面传递的id,在下面获取数据的时候先提交id
    this.groupId = this.$route.query.groupId
    this.groupName = this.$route.query.groupName
  },
  mounted: function () {
    this.getData(this.groupId, this.currentPage)
  },

created:实例已经创建完成之后被调用。在这一步,实例已完成以下的配置:数据观测(data observer),属性和方法的运算, watch/event 事件回调。然而,挂载阶段还没开始,el 属性目前不可见。我们这里在created中执行了获取上个页面传来的数据
mounted:el 被新创建的 vm.$el 替换,并挂载到实例上去之后调用该钩子。我们这里在mounted中执行了获取初始数据功能。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,657评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,889评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,057评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,509评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,562评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,443评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,251评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,129评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,561评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,779评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,902评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,621评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,220评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,838评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,971评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,025评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,843评论 2 354

推荐阅读更多精彩内容

  • # 传智播客vue 学习## 1. 什么是 Vue.js* Vue 开发手机 APP 需要借助于 Weex* Vu...
    再见天才阅读 3,540评论 0 6
  • 这篇笔记主要包含 Vue 2 不同于 Vue 1 或者特有的内容,还有我对于 Vue 1.0 印象不深的内容。关于...
    云之外阅读 5,050评论 0 29
  • 一:什么是闭包?闭包的用处? (1)闭包就是能够读取其他函数内部变量的函数。在本质上,闭包就 是将函数内部和函数外...
    xuguibin阅读 9,603评论 1 52
  • 你大概是我躲不过的一场雨。打湿眼睛也压得心透不过气。可是雨总会停,天总会放晴,我跑远一点总可以绕过你,也总会有一天...
    娃娃脸闯天下阅读 382评论 0 0
  • 书山文海烦死了!什么都无趣,无趣也是无力呀!啊……。真想喊几嗓!
    简芽儿阅读 149评论 0 0