vue Examples模板

vue Examples模板 通过script引入使用vue 非使用脚手架
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
    <div id="app">{{message}}</div>
</body>
<script type="text/javascript" src='js/vue.min.js'></script>
<script type="text/javascript">
	//注册全局组件常用选项
	Vue.component('myarticl',{
		props:[],
		template:``,
		render:function(){},
		data:function(){},
		computed:{},
		//组件里面插入子组件
		components:{},
		methods:{},
		watch:{},
		mounted:{},
		filters:{}
	})
	// Vue 实例常用选项
	new Vue({
		// 1. 实例挂载目标
		el:'#app',
		// 2. 设置数据对象
		data:{
			num1: 12,
			num2: 13.3,
		}
		// 3. 计算属性
		computed:{
			//ES6 写法
			sum(){
				return this.num1+this.num2
			}
		}
		// 4. methods 方法
		methods:{
 			plus(){
 				return this.num1+this.num2//
 			}
		}
		// 5.watch 观察
		watch:{
			num(){
				console.log('有变化了:' this.num1);
			}
		}
		// 6. 生命钩子函数
		mounted:{
			//挂载到实例上调用该函数
			var _this=this;
            //为productList添加select(是否选中)字段,初始值为true
            this.productList.map(function (item) {
                _this.$set(item, 'select', true);
            })
		}
		// 7.自定义局部指令
		directives:{
			tack:{
				inserted(el){
					el.style.color='red'
				}
			},
			focus: {
		    // 指令的定义
		    inserted: function (el) {
		      el.focus()
		    }
  		}		
		}
		// 8.局部注册组件
		components:{
			'my-article':{
    		props:['detail'],
    		template:`<div>
            <div>
            <h1>{{detail.title}}</h1>
            <div>
            <span>{{detail.date}}</span>
            <span v-show="detail.is_original">原创</span>
            </div>
            </div>
            <img :src="detail.cover_url" alt="">
            </div>`
    	}
		}
		// 9.过滤器
		filters:{
			//ES6 写法
			toInt(value){
				return parseInt(value);
			}
		}
	})
</script>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端鼓励师

老铁 支持一波

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值