vue sample
<template>
<section>
<header class="top_tips">
<span class="num_tip" v-if="fatherComponent == 'home'">{{level}}</span>
<span class="num_tip" v-if="fatherComponent == 'item'">题目{{itemNum}}</span>
</header>
<div v-if="fatherComponent == 'home'" >
<div class="home_logo item_container_style"></div>
<router-link to="item" class="start button_style" ></router-link>
</div>
<div v-if="fatherComponent == 'item'" >
<div class="item_back item_container_style">
<div class="item_list_container" v-if="itemDetail.length > 0">
<header class="item_title">{{itemDetail[itemNum-1].topic_name}}</header>
<ul>
<li v-for="(item, index) in itemDetail[itemNum-1].topic_answer" @click="choosed(index, item.topic_answer_id)" class="item_list">
<span class="option_style" v-bind:class="{'has_choosed':choosedNum==index}">{{chooseType(index)}}</span>
<span class="option_detail">{{item.answer_name}}</span>
</li>
</ul>
</div>
</div>
<span class="next_item button_style" @click="nextItem" v-if="itemNum < itemDetail.length"></span>
<span class="submit_item button_style" v-else @click="submitAnswer"></span>
</div>
</section>
</template> <script>
import { mapState, mapActions } from 'vuex'
export default {
name: 'itemcontainer',
data() {
return {
itemId: null, //题目ID
choosedNum: null, //选中答案索引
choosedId:null //选中答案id
}
},
props:['fatherComponent'],
computed: mapState([
'itemNum', //第几题
'level', //第几周
'itemDetail', //题目详情
'timer', //计时器
]),
methods: {
...mapActions([
'addNum', 'initializeData',
]),
//点击下一题
nextItem(){
if (this.choosedNum !== null) {
this.choosedNum = null;
//保存答案, 题目索引加一,跳到下一题
this.addNum(this.choosedId)
}else{
alert('您还没有选择答案哦')
}
},
//索引0-3对应答案A-B
chooseType: type => {
switch(type){
case 0: return 'A';
case 1: return 'B';
case 2: return 'C';
case 3: return 'D';
}
},
//选中的答案信息
choosed(type,id){
this.choosedNum = type;
this.choosedId = id;
},
//到达最后一题,交卷,请空定时器,跳转分数页面
submitAnswer(){
if (this.choosedNum !== null) {
this.addNum(this.choosedId)
clearInterval(this.timer)
this.$router.push('score')
}else{
alert('您还没有选择答案哦')
}
},
},
created(){
//初始化信息
if(this.fatherComponent == 'home') {
this.initializeData();
document.body.style.backgroundImage = 'url(./static/img/1-1.jpg)';
}
}
}
</script> <style lang="less">
.top_tips{
position: absolute;
height: 7.35rem;
width: 3.25rem;
top: -1.3rem;
right: 1.6rem;
background: url(../images/WechatIMG2.png) no-repeat;
background-size: 100% 100%;
z-index: 10;
.num_tip{
position: absolute;
left: 0.48rem;
bottom: 1.1rem;
height: 0.7rem;
width: 2.5rem;
font-size: 0.6rem;
font-family: '黑体';
font-weight: 600;
color: #a57c50;
text-align: center;
}
}
.item_container_style{
height: 11.625rem;
width: 13.15rem;
background-repeat: no-repeat;
position: absolute;
top: 4.1rem;
left: 1rem;
}
.home_logo{
background-image: url(../images/1-2.png);
background-size: 13.142rem 100%;
background-position: right center;
}
.item_back{
background-image: url(../images/2-1.png);
background-size: 100% 100%;
}
.button_style{
display: block;
height: 2.1rem;
width: 4.35rem;
background-size: 100% 100%;
position: absolute;
top: 16.5rem;
left: 50%;
margin-left: -2.4rem;
background-repeat: no-repeat;
}
.start{
background-image: url(../images/1-4.png);
}
.next_item{
background-image: url(../images/2-2.png);
}
.submit_item{
background-image: url(../images/3-1.png);
}
.item_list_container{
position: absolute;
height: 7.0rem;
width: 8.0rem;
top: 2.4rem;
left: 3rem;
-webkit-font-smoothing: antialiased;
}
.item_title{
font-size: 0.65rem;
color: #00e;
line-height: 0.7rem;
}
.item_list{
font-size: 0;
margin-top: 0.4rem;
width: 10rem;
span{
display: inline-block;
font-size: 0.6rem;
color: #00e;
vertical-align: middle;
}
.option_style{
height: 0.725rem;
width: 0.725rem;
border: 1px solid #fff;
border-radius: 50%;
line-height: 0.725rem;
text-align: center;
margin-right: 0.3rem;
font-size: 0.5rem;
font-family: 'Arial';
}
.has_choosed{
background-color: #ffd400;
color: #575757;
border-color: #ffd400;
}
.option_detail{
width: 7.5rem;
padding-top: 0.11rem;
}
}
</style>
单独来讲, Vue.js 被定义成一个用来开发 Web 界面的前端库,是个非常轻量级的工具。
Vue.js 本身具有响应式编程和组件化的特点。
Vue.js 的组件化理念和 ReactJS 异曲同工——“一切都是组件”,可以将任意封装好的代
第 1章 Vue.js 简介
码注册成标签,例如:Vue.component('example', Example),可以在模板中以 <example></
example> 的形式调用。如果组件抽象得合理,这在很大程度上能减少重复开发,而且配合
Vue.js 的周边工具 vue-loader,我们可以将一个组件的 CSS、HTML 和 js 都写在一个文件里,
做到模块化的开发。
除此之外,Vue.js 也可以和一些周边工具配合起来,例如 vue-router 和 vue-resource,
支持了路由和异步请求,这样就满足了开发单页面应用的基本条件。
作为新兴的前端框架,Vue.js 也抛弃了对 IE8 的支持,在移动端支持到 Android 4.2+ 和 iOS 7+。
另外,在传统的前后端混合(通过后端模板引擎渲染)的
项目中,Vue.js 也会受到一定的限制,Vue 实例只能和后端模板文件混合在一起,获取的数
据也需要依赖于后端的渲染,这在处理一些 JSON 对象和数组的时候会有些麻烦。
理想状态下,我们能直接在前后端分离的新项目中使用 Vue.js 最合适。这能最大程度上
发挥 Vue.js 的优势和特性,熟悉后能极大的提升我们的开发效率以及代码的复用率。尤其是
移动浏览器上,Vue.js 压缩后只有 18KB,而且没有其他的依赖。
第一个特性是数据绑定
第二个特性是组件化
vue sample的更多相关文章
- Vue vs React: Javascript 框架之战
		
https://baijiahao.baidu.com/s?id=1608210396818353443&wfr=spider&for=pc 原文档 正如我们之前提到的,Word ...
 - 简简单单的Vue3(插件开发,路由系统,状态管理)
		
既然选择了远方,便只顾风雨兼程 __ HANS许 系列:零基础搭建前后端分离项目 系列:零基础搭建前后端分离项目 插件 路由(vue-router) 状态管理模式(Vuex) 那在上篇文章,我们讲了, ...
 - 简简单单的Vue2(简单语法,生命周期,组件)
		
既然选择了远方,便只顾风雨兼程! __HANS许 系列:零基础搭建前后端分离项目 系列:零基础搭建前后端分离项目 简单入手 组件 在上面文章,我们简单的讲了前端框架的工程化,也就是MVVM,还有特别聊 ...
 - Vue 2.0 Application Sample
		
===搭建Demo=== http://blog.csdn.net/wangjiaohome/article/details/51728217 ===单页Application=== http://b ...
 - 关于vue指令(directive)
		
1.指令的注册 指令跟组件一样需要注册才能使用,同样有两种方式,一种是全局注册: Vue.directive('dirName',function(){ //定义指令 }); 另外一种是局部注册: n ...
 - SpringBoot  vue
		
springboot 整合vue就行前后端完全分离,监听器,过滤器,拦截器 https://github.com/ninuxGithub/spring-boot-vue-separateA blog ...
 - Vue:如何在地图上添加自定义覆盖物(点)
		
目录 如何在地图上添加自定义覆盖物(点) 首发日期:2019-1-25 如何在地图上添加自定义覆盖物(点) 此文重点是在地图上标点,所以就省去引入百度地图的步骤了. 先给一下最终的效果. 这个效果主要 ...
 - 通过webpack2从0开始配置自己的vue项目 1
		
PS 阅读者需要node基础.webpack原理知识.vue基础 安装node 这个网上很多教程 打开终端 创建项目 npm init 全局安装: cnpm i webpack webpack-dev ...
 - vue axios 与 FormData 结合 提交文件 上传文件
		
---再利用Vue.axios.FormData做上传文件时,遇到一个问题,后台虽然接收到请求,但是将文件类型识别成了字符串,所以,web端一直报500,结果是自己大意了. 1.因为使用了new F ...
 
随机推荐
- linux centos7 开启 mysql 3306 端口 外网访问 的实践
			
第〇步:思路 3306 端口能否被外网访问,主要要考虑: (1)mysql的3306 端口是否开启?是否没有更改端口号? (2)mysql 是否允许3306 被外网访问? (3)linux 是否已经开 ...
 - springboot使用activemq同时接收queue和topic消息
			
原文链接:https://blog.csdn.net/jia_costa/article/details/79354478 新建springboot项目, pom文件如下 <?xml versi ...
 - eclipse搭建springboot的项目
			
记录一次自己搭建springboot的经历 springboot项目创建 这里借用别的博主分享的方法 https://blog.csdn.net/mousede/article/details/812 ...
 - linux中查看磁盘容量的常用操作
			
linux中查看磁盘容量常用操作 实验室有GPU集群,用户跑数据时候跑着跑着会出现集群挂掉的问题,原因就是,在跑数据时,用户上传文件,数据集,系统产生缓存等一系列操作,消耗了集群空间,师兄让我清理下服 ...
 - Mac10.14.6安装并破解PyCharm
			
之前安装了PyCharm的Community版本, 用了半天之后发现好多功能都没有, 于是准备安装专业版然后破解. 安装包直接去官网下载, 不多说. 破解补丁的下载地址如下: 链接:https://p ...
 - 【转帖】一文看懂docker容器技术架构及其中的各个模块
			
一文看懂docker容器技术架构及其中的各个模块 原创 波波说运维 2019-09-29 00:01:00 https://www.toutiao.com/a6740234030798602763/ ...
 - Servlet 响应及请求信息
			
// 文件路径 D:\ApacheServer\web_java\HelloWorld\src\com\test\TestServletRequestrResponse.java package co ...
 - GstStaticCaps的初始化
			
struct _GstStaticCaps { /*< public >*/ GstCaps *caps; const char *string; /*< private >* ...
 - Tree Generator™ CodeForces - 1149C (线段树,括号序列)
			
大意: 给定括号序列, 每次询问交换两个括号, 求括号树的直径. 用[ZJOI2007]捉迷藏的方法维护即可. #include <iostream> #include <algor ...
 - (二)ActiveMQ之点对点消息实现
			
一.点对点消息实现概念 在点对点或队列模型下,一个生产者向一个特定的队列发布消息,一个消费者从该队列中读取消息.这里,生产者知道消费者的队列,并直接将消息发送到消费者的队列.这种模式被概括为:只有一个 ...