VUE小案例--简易计算器
这个小案例主要时练习v-model的使用,功能并不完善
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./lib/vue-2.4.0.js"></script>
</head>
<body>
<div id="app">
<input type="text" v-model="n1"> <select v-model="opt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select> <input type="text" v-model="n2"> <input type="button" value="=" @click="calc"> <input type="text" v-model="result">
</div> <script>
// 创建 Vue 实例,得到 ViewModel
var vm = new Vue({
el: '#app',
data: {
n1: 0,
n2: 0,
result: 0,
opt: '+'
},
methods: {
calc(){ // 计算器算数的方法
// 逻辑:
switch(this.opt){
case '+':
this.result = parseInt(this.n1) + parseInt(this.n2);
break;
case '-':
this.result = parseInt(this.n1) - parseInt(this.n2);
break;
case '*':
this.result = parseInt(this.n1) * parseInt(this.n2);
break;
case '/':
this.result = parseInt(this.n1) / parseInt(this.n2);
break;
}
}
}
});
</script>
</body>
</html>
VUE小案例--简易计算器的更多相关文章
- vue小案例--简易评论区
一.小案例(评论区) 1.流程 (1)分析静态页面.(vue项目创建参考https://www.cnblogs.com/l-y-h/p/11241503.html)(2)拆分静态页面,变成一个个组件. ...
- 微信小程序-简易计算器
代码地址如下:http://www.demodashi.com/demo/14210.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
- Vue小案例 之 商品管理------学习过滤器 使用过滤器处理日期的格式
代码学习过滤器 过滤器介绍:过滤模型数据,在数据显示前做预处理操作: 内置过滤器:在1.x中,Vue提供了内置过滤器,但是在2.x中已经完全废除: 解决办法: (1)使用第三方库来替代1.x中的内置过 ...
- Vue小案例(一)
案例需求: 创建一个品牌展示表格,表头有编号(id),品牌名称(name),创建时间(time)和操作,需要实现的功能是对数据的增删操作,和时间的格式化. 思路分析:在开发之前需要想清楚要用到Vue中 ...
- VUE小案例--跑马灯效果
自学Vue课程中学到的一个小案例,跑马灯效果 <!DOCTYPE html> <html lang="zh-CN"> <head> <me ...
- Vue(小案例_vue+axios仿手机app)_go实现退回上一个路由
一.前言 this.$router.go(-1)返回上级路由 二.主要内容 1.小功能演示: 2.组件之间的嵌套关系为: 3.具体实现 (1)由于这种返回按钮在每个页面中的结构都是一样的,只是里面的数 ...
- 微信小程序 - 实战小案例 - 简易记事本
多项技能,好像也不错.学习一下微信小程序. 教程:https://mp.weixin.qq.com/debug/wxadoc/dev/ 简介:一套用来开发在手机微信上运行的app框架,不用安装 组成: ...
- Vue(小案例_vue+axios仿手机app)_Vuex优化购物车功能
一.前言 1.用vuex实现加入购物车操作 2.购物车详情页面 3.点击删除按钮,删除购物详情页面里的对应商品 二.主要内容 1.用vuex加入购物车 (1)在src ...
- Vue(小案例_vue+axios仿手机app)_购物车(二模拟淘宝购物车页面,点击加减做出相应变化)
一.前言 在上篇购物车中,如果用户刷新了当前的页面,底部导航中的数据又会恢复为原来的: 1.解决刷新,购物车上数值不变 ...
随机推荐
- 将postgresql中的数据实时同步到kafka中
参考地址:https://blog.csdn.net/weixin_33985507/article/details/92460419 参考地址:https://mp.weixin.qq.com/s/ ...
- bzoj4408 [Fjoi 2016]神秘数 & bzoj4299 Codechef FRBSUM 主席树+二分+贪心
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4299 https://lydsy.com/JudgeOnline/problem.php?id ...
- windows下如何安装pip
在安装pip前,请确认win系统中已经安装好了python,和easy_install工具 Python完成后 配置环境变量 在环境变量中添加Python目录 (1) 右键点击"计算机&qu ...
- 【leetcode】1031. Maximum Sum of Two Non-Overlapping Subarrays
题目如下: Given an array A of non-negative integers, return the maximum sum of elements in two non-overl ...
- Python3解leetcode Subtree of Another Tree
问题描述: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure ...
- ubuntu18.04-安装最新cmake
https://www.linuxidc.com/Linux/2018-09/154165.htm
- 【HDOJ6662】Acesrc and Travel(树形DP,换根)
题意:有一棵n个点的树,每个点上有两个值a[i],b[i] A和B在树上行动,A到达i能得到a[i]的偷税值,B能得到b[i],每次行动只能选择相邻的点作为目标 两个人都想最大化自己的偷税值和对方的差 ...
- 【2019 Multi-University Training Contest 7】
01:https://www.cnblogs.com/myx12345/p/11653845.html 02: 03: 04: 05: 06:https://www.cnblogs.com/myx12 ...
- Java继承基础版
继承是软件开发中实现代码复用的有效手段,如果一个类A继承了类B那么类B中的public.protected及默认修饰符修饰的实例成员或静态成员将被类A继承,也可以说类B的成员就是类A的成员而类A在此基 ...
- macOS 10.14 Mojave Apache Setup: Multiple PHP Versions
Part 1: macOS 10.14 Mojave Web Development Environment Developing web applications on macOS is a rea ...