当前位置: 首页 > news >正文

学校网站建设开发合肥网络科技有限公司

学校网站建设开发,合肥网络科技有限公司,php网页制作作业,衣服定制app真的好久没有更新博客了,但是我最近并没有偷懒哦,一直在学习vue这个框架,并且用它做了一个小项目,现在就给大家分享一下我的这个还比较有意思的小项目咯,本项目是基于vue2.0开发的。 灵感来源 这是一个数据可视化相关的…

真的好久没有更新博客了,但是我最近并没有偷懒哦,一直在学习vue这个框架,并且用它做了一个小项目,现在就给大家分享一下我的这个还比较有意思的小项目咯,本项目是基于vue2.0开发的。

灵感来源

这是一个数据可视化相关的项目,作为一个学生班主任,需要对班上同学的各方面的情况都有所了解,于是我便做了一个问卷调查来了解学生各方面的情况。然后我又想到可以分析我们班的群聊记录呀,根据群聊记录可以得到班上同学之间的亲密度和班级群聊活跃度等信息。自然而然,我就想着可以搭建一个平台来展示这些数据,既然是数据当然是以图表的方式来展示更加直观,然后折中选择了echarts这个图标库。至于为什么要选择用vue这个插件,之前只是觉得学了vue可以练练手,做完之后发现vue真的很轻量也很好上手,结合vuex和vue-router基本能完成我项目中的所有需求。

在线展示:http://119.29.57.165:8080/family 
源码:https://github.com/hieeyh/tong2-family 
本教程是基于你已经有一定vue基础之上的,如果你还不了解什么是vue建议先去学习一下

项目初始构建

首先全局安装vue-cli,vue-cli是vue自己的项目构建工具,几个简单的步骤就可以帮助你快速构建一个vue项目。

npm install -g vue-cli

然后,利用vue-cli构建一个vue项目

# 创建一个基于 "webpack" 模板的新项目
$ vue init webpack family
# 安装依赖
$ cd family
$ npm install

项目文件解释

  • build中是webpack基本配置文件,开发环境配置文件,生产环节配置文件

  • node_modules是各种依赖模块

  • src中是vue组件及入口文件

  • static中放置静态文件

  • index.html是页面入口文件

基本页面实现

项目创建好之后,就开始实现自己想要的页面了,修改src文件夹下的App.vue文件,如下:

<template>
<div id="#app">
<!-- 导航栏 --><my-head></my-head><my-nav></my-nav><transition><router-view></router-view></transition><my-foot></my-foot>
</div>
</template><script>
import myHead from './components/header'
import myNav from './components/nav'
import myFoot from './components/foot'export default {name: 'app',components: {myHead,myNav,myFoot}
}
</script>

myHead组件是页面头部,myNav组件是页面左侧导航栏,myFoot是页面底部,router-view组件是vue-router中渲染路径匹配到的视图组件。每个组件的具体实现可以去github项目地址去看源码。

创建配置路由

显然,我要做的是一个单页面应用,要用到vue-router,先安装vue-router,输入如下命令:

npm install --save vue-router

然后,在src文件夹下面的main.js文件中添加路由相关的代码,如下:

import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'Vue.use(VueRouter) 
// 定义路由组件
const Worldcloud = require('./components/cloud.vue')
const Building = require('./components/building.vue')
const Canteen = require('./components/canteen.vue')
const Selfstudy = require('./components/selfstudy.vue')
const Difficult = require('./components/difficult.vue')
const Interest = require('./components/interest.vue')
const Bedroom = require('./components/bedroom.vue')
const Graduate = require('./components/graduate.vue')
const Getup = require('./components/getup.vue')
const Gotobed = require('./components/gotobed.vue')
const Eat = require('./components/eat.vue')
const Amuse = require('./components/amuse.vue')
const Single = require('./components/single.vue')
const Chat = require('./components/chat.vue')
const Onlyme = require('./components/onlyme.vue')// 定义路由,配置路由映射
const routes = [{ path: '/', redirect: '/wordcloud' },{ path: '/wordcloud', component: Worldcloud },{ path: '/building', component: Building },{ path: '/canteen', component: Canteen },{ path: '/selfstudy', component: Selfstudy },{ path: '/difficult', component: Difficult },{ path: '/interest', component: Interest },{ path: '/bedroom', component: Bedroom },{ path: '/graduate', component: Graduate },{ path: '/getup', component: Getup },{ path: '/gotobed', component: Gotobed },{ path: '/eat', component: Eat },{ path: '/amuse', component: Amuse },{ path: '/single', component: Single },{ path: '/chat', component: Chat },{ path: '/onlyme', component: Onlyme }
]new Vue({el: '#app',template: '<App/>',components: { App },router
})

从路由映射的配置中可以看出,访问网站的根路由会直接跳转到/wordcloud。路由映射的组件中用到了百度的echarts库,这是一个很好用的图表库。

怎么画图

怎么用echarts画图呢?其实官网上有很多实例,下面以bedroom.vue组件为例来简单说明,bedroom.vue代码如下:

<template><div class="main_content"><div id="bedroom"></div></div>
</template>
<script>import echarts from 'echarts'export default {data() {return {chart: null,opinion: ['学习氛围差', '学习氛围一般', '学习氛围很好'],opinionData: [{value:26, name:'学习氛围差'},{value:31, name:'学习氛围一般'},{value:8, name:'学习氛围很好'}]}},methods: {drawPie (id) {this.chart = echarts.init(document.getElementById(id))this.chart.setOption({title: {text: '寝室学习氛围情况调查',left: 'center',top: 10,textStyle: {fontSize: 24,fontFamily: 'Helvetica',fontWeight: 400}},tooltip: {trigger: 'item',formatte: "{b}: {c} ({d}%)"},toolbox: {feature: {saveAsImage: {},dataView: {}},right: 15,top: 10},legend: {orient: 'vertical',left: 5,top: 10,data: this.opinion,},series: [{name: '寝室学习氛围',type: 'pie',radius: ['50%', '70%'],center: ['50%', '60%'],avoidLabelOverlap: false,label: {emphasis: {show: true,textStyle: {fontSize: '24',fontWeight: 'bold'}}},labelLine: {normal: {show: false}},data: this.opinionData,itemStyle: {emphasis: {shadowBlur: 10,shadowOffset: 0,shadowColor: 'rgba(0, 0, 0, 0.5)'}}}]})}},mounted() {this.$nextTick(function() {this.drawPie('bedroom')})}}
</script>
<style scoped>
#bedroom {position: relative;left: 50%;margin-left: -400px;margin-bottom: 70px;width: 800px;height: 600px;border: solid #D01257 1px;box-shadow: 0 0 8px #FB90B7;border-radius: 10px;
}   
</style>

这是一个vue的单文件组件,script中,首先导入echarts库,前提是已经安装了echarts库,输入以下命令安装:

npm install --save echarts

data对象中是画图要用到的一些数据,drawpie方法用来画图,接收一个DOM对象,然后在mounted构子函数中调用drawpie即可。

两点说明

  1. drawpie方法接收的DOM对象需要有确定的宽高,否则图像不显示

  2. mounted中要包含vm.$nextTick才能保证该实例已经插入文档

实现登录功能

登录功能基于vuex(vue状态管理)和浏览器的sessionStorage实现的。首先在src文件夹下新建store文件夹,存放vuex的store(仓库),新建三个文件store.js、login.js、user.js。login.js中存储登录状态,user.js中存储用户登录信息,store.js加载login和user模块。

注意:在store.js中要引入babel-polyfill(先安装),否则会报错,报错原因是Babel默认只转换新的JavaScript句法,而不转换新的API,比如Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise等全局对象,以及一些定义在全局对象上的方法都不会转码。所以必须使用babel-polyfill,为当前环境提供一个垫片。

然后修改main.js文件,引入store:

import store from './store/store'
...
...
new Vue({el: '#app',template: '<App/>',components: { App },router,store
})

修改App.vue文件,如下:

<template>
<div id="#app">
<!-- 导航栏 --><my-head></my-head><my-nav></my-nav><transition><router-view></router-view></transition><my-mask v-if="canlogin"></my-mask><my-login v-if="canlogin"></my-login><my-foot></my-foot>
</div>
</template>
<script>
...
import myMask from './components/mask'
import myLogin from './components/login'export default {...data() {return {canlogin: false}},computed: {canlogin() {return this.$store.state.login.islogin}}
}
</script>

到此,就基本上大功告成了,在命令行中输入 npm run dev预览一下。

项目发布

项目可以在本地预览了,但是要怎么发布到网上呢?首先,在命令行中输入

npm run build

会生成一个dist文件夹,该文件夹中就是我们可以用来发布的代码,直接将代码上传到你的服务器上就可以啦。

转载https://segmentfault.com/a/1190000007521014

http://www.lbrq.cn/news/2482669.html

相关文章:

  • 深圳建设局官方网站网页设计需要学什么
  • python做视频点播网站域名怎么注册
  • seo的主要分析工具seo快排软件
  • 杭州市建设网站培训教育机构
  • 如何查看网站权重百度直接打开
  • 做餐饮酒店网站2024年的新闻
  • 天津建设银行公积金缴费网站免费域名申请个人网站
  • 企业宣传网站建设百度开户代理公司
  • 做国外衣服的网站有哪些长尾关键词是什么意思
  • 武汉网站建设yundaow如何做地推推广技巧
  • 济南网站免费制作最火的推广软件
  • 陕西省私募基金协会淘宝关键词优化怎么弄
  • 贵阳做网站的拉新推广渠道
  • 做网咖的网站推广优化seo
  • asp网站模版安装安装百度到手机桌面
  • 网站建设哪家稳妥正规的教育培训机构有哪些
  • 怎样建网站得花多少钱如何给公司网站做推广
  • 上海二手房seo查询seo优化
  • 怎么制作自己的头像logo南宁百度推广seo
  • 易企秀可以做网站吗公司官网怎么制作
  • 网站后台尺寸一般做多大的热门网站排名
  • 中山移动网站建设怎么做免费建立一个网站
  • 目前网站建设主流技术架构怎样建网站平台
  • 公司简介模板素材进行优化
  • 网站策划与维护怎么做谷歌推广
  • 做视频网站需要什么服务器配置刷百度关键词排名
  • wordpress一键搬家给网站做seo的价格
  • 沙市网站建设国内设计公司前十名
  • 广州做网站专业公司昆明新闻头条最新消息
  • 西安网站优化招聘软件开发公司联系方式
  • Ubuntu 18.04安装Fast-Lio2教程
  • IntelliJ IDEA 中左上方未显示项目根目录问题
  • python I 本地 html 文件读取方法及编码报错问题详解
  • Spring Boot 实战:用 Apache Commons CSV 优雅解析 CSV 文件
  • Lua(面向对象)
  • 【lucene】AttributeSource概述