为了学习基础语法,我并没有用vue-cli脚手架来vue init [基于什么类型]  [项目名称]初始化项目,而是直接<script>../vue.js</script>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
模板语法(各种指令、Mustache)
<div v-bind:class="clas">666</div>
<button v-on:click="say(678)">按钮</button> <p></p>计算属性和观察者
<div>
<input type="text" v-model="ipt">
</div> <div>{{toUp}}</div>
<input type="text" v-model="ipt2"> <p></p>自定义指令
<div v-color="'green'">用于测试</div> <p></p>自定义组件[简单]
<div>
<simple></simple>
</div> <p></p>自定义组件[复杂]
<div>
<do-list v-bind:data="list"></do-list>
</div>
</div>
<script src="./bower_components/vue/dist/vue.min.js"></script>
<script>
// 注册一个全局自定义【指令】 v-color
Vue.directive("color", function(el,binding){ /* el就是页面的dom */
console.log(binding)
el.style.color = binding.value;
}) // 注册一个全局自定义组件 v-color
Vue.component("simple",Vue.extend({
template: '<div>A custom component!</div>'
})) // 注册一个复杂全局自定义【组件】 v-color
Vue.component("do-list",Vue.extend({
//(父子传参)子组件要显式地用 props 选项声明它预期的数据:
props: ['data'],
template: `
<ul>
<li v-for="item in data">{{item.name}}</li>
</ul>
`
})) //一个vue的实例
new Vue({
el: '#app', //model
data: {
msg: 'Hello!',
clas:'active',
ipt:'dsh',
ipt2:'wx',
list:[
{name:'小明',age:20},
{name:'小红',age:16}
]
}, //计算属性
computed:{
toUp:function() {
var that=this;
var temp=that.ipt.toUpperCase();
return temp;
}
}, //函数
methods:{
say:function(i) {
alert(i)
}
}, //观察者
watch:{
// 如果 `ipt2` 发生改变,这个函数就会运行
ipt2:function (newVal) {
this.say(newVal)
//console.log(this.ipt2);
}
} //至于路由,我暂时先用官方支持的 vue-router 库,而不用基础的自带路由
}) </script>
</body>
</html>

动态显示时间和过滤器

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
当前时间:{{nowDate | dataFmt('yyyy-MM-dd HH:mm:ss')}}
</div>
<script src="./bower_components/vue/dist/vue.min.js"></script>
<script>
// vue2.0后,删除了所有内置的过滤器,都需要自己定义
Vue.filter('dataFmt',function(data,type){
that = new Date(data)
var o = {
"M+": that.getMonth() + 1, //月份
"d+": that.getDate(), //日
"h+": that.getHours() % 12 == 0 ? 12 : that.getHours() % 12, //小时
"H+": that.getHours(), //小时
"m+": that.getMinutes(), //分
"s+": that.getSeconds(), //秒
"q+": Math.floor((that.getMonth() + 3) / 3), //季度
"S": that.getMilliseconds() //毫秒
};
var week = { "0": "\u65e5", "1": "\u4e00", "2": "\u4e8c", "3": "\u4e09", "4": "\u56db", "5": "\u4e94", "6": "\u516d" };
if (/(y+)/.test(type)) { type = type.replace(RegExp.$1, (that.getFullYear() + "").substr(4 - RegExp.$1.length)); }
if (/(E+)/.test(type)) { type = type.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "\u661f\u671f" : "\u5468") : "") + '周' + week[that.getDay() + ""]); }
for (var k in o) {
if (new RegExp("(" + k + ")").test(type)) { type = type.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); }
}
return type;
}) //一个vue的实例
new Vue({
el: '#app',
data: {
nowDate:new Date()
}, //生命周期函数:动态显示时间,要不然时间是死的,刷新页面才会更新
mounted: function () {
var that=this;
setInterval(function () {
that.nowDate=new Date();
},1000)
}
})
</script>
</body>
</html>

vue简单demo的更多相关文章

  1. vue+node+es6+webpack创建简单vue的demo

    闲聊: 小颖之前一直说是写一篇用vue做的简单demo的文章,然而小颖总是给自己找借口,说没时间,这一没时间一下就推到现在了,今天抽时间把这个简单的demo整理下,给大家分享出来,希望对大家也有所帮助 ...

  2. 一个基于ES5的vue小demo

    由于现在很多vue项目都是基于ES6开发的,而我学vue的时候大多是看vue官网的API,是基于ES5的,所以对于刚接触项目的我来说要转变为项目的模块化写法确实有些挑战.因此,我打算先做一个基于ES5 ...

  3. 设计模式之单例模式的简单demo

    /* * 设计模式之单例模式的简单demo */ class Single { /* * 创建一个本类对象. * 和get/set方法思想一样,类不能直接调用对象 * 所以用private限制权限 * ...

  4. Spring的简单demo

    ---------------------------------------- 开发一个Spring的简单Demo,具体的步骤如下: 1.构造一个maven项目 2.在maven项目的pom.xml ...

  5. 使用Spring缓存的简单Demo

    使用Spring缓存的简单Demo 1. 首先创建Maven工程,在Pom中配置 <dependency> <groupId>org.springframework</g ...

  6. Managed DirectX中的DirectShow应用(简单Demo及源码)

    阅读目录 介绍 准备工作 环境搭建 简单Demo 显示效果 其他 Demo下载 介绍 DirectX是Microsoft开发的基于Windows平台的一组API,它是为高速的实时动画渲染.交互式音乐和 ...

  7. angular实现了一个简单demo,angular-weibo-favorites

    前面必须说一段 帮客户做了一个过渡期的项目,唯一的要求就是速度,我只是会点儿基础的php,于是就用tp帮客户做了这个项目.最近和客户架构沟通,后期想把项目重新做一下,就用现在最流行的技术,暂时想的使用 ...

  8. Solr配置与简单Demo[转]

    Solr配置与简单Demo 简介: solr是基于Lucene Java搜索库的企业级全文搜索引擎,目前是apache的一个项目.它的官方网址在http://lucene.apache.org/sol ...

  9. 二维码简单Demo

    二维码简单Demo 一.视图 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name=&qu ...

随机推荐

  1. Mac 文件读写权限问题 OSError: Operation not permitted

    Mac在OS X 10.11以后加入了Rootless功能,主要是限制了root权限,阻止用户对部分路径下的目录进行更改.受到限制的有以下目录: /System /bin /sbin /usr (ex ...

  2. js post

    在进行html5页面的设计时,希望用户加载完成页面后,进行交互时只改变其中的某些元素的内容,这样更像本地APP的呈现效果,但是HTML中的post.get如果使用submit进行提交的话会直接使用返回 ...

  3. Swig 使用指南 (express模板)

    如何使用 API swig.init({ allowErrors: false, autoescape: true, cache: true, encoding: 'utf8', filters: { ...

  4. 编程之美 set 2 精确表达浮点数

    有限小数和无限循环小数转化成分数 比如 0.9 ->  9/10 0.333(3) -> 1/3 解法 1. 主要涉及到一个数学公式的计算. 2. 对于有限小数, 分子分母求最大公约数即可 ...

  5. 剑指 offer set 13 把数组排成最小的数

    总结 1. 给定 3, 32, 321 将他们组合成最小的数, 比如 321323 2. 3    ->   333 32   ->   322 321 ->   321 然后再排序

  6. 自定义控件_VIewPager显示多个Item

    一直以来想搞明白这个不完全的VIewPager是怎么做到的,有幸看到这片篇文章 有二种实现方法 1.设置的属性 1.clipChildren属性 2.setPageMargin 3.更新Item外界面 ...

  7. 用Dialog 做自定义动画,加播放监听

    final Dialog customDialog = new Dialog(this); customDialog.setTitle(R.string.attention); customDialo ...

  8. Arduino开发版学习计划--小车的行走

    小车的前进后退,左右转弯 代码如下 void motor(char pin,char pwmpin,char state,int val) { pinMode(pin, OUTPUT); ) { an ...

  9. [iOS微博项目 - 4.2] - 设置转发微博背景

    github: https://github.com/hellovoidworld/HVWWeibo A.转发微博部分的淡灰色背景 1.需求 转发微博部分需要设置背景色 使用图片作为背景   2.思路 ...

  10. Limits on Table Column Count and Row Size Databases and Tables Table Size 最大行数

    MySQL :: MySQL 8.0 Reference Manual :: C.10.4 Limits on Table Column Count and Row Size https://dev. ...