2020/07/01 Vue - 一直在更新

首先,我们先了解一个.vue页面的组成

<template>
	   模板部分:这个页面的html部分
</template>
<script>
	   js部分: 引入,以及数据处理部分
</script>
<style>
	   css部分:样式
</style>

重点了解<scirpt></scirpt>里面的相关内容
分为
外部文件的引入:

import { dataSource } from '../assets/js/dataSource' 
import { AComponent } from '../components/AComponents' 
import { Button, Swipe, SwipeItem } from 'vant'

主体部分:

export default {
	属性||方法:{
		xxx:function(){}
	} || [] || "" || `` || Component || else ,
	...
}

主体部分有以下属性:

el //id,绑定实例
name //组件的名字
data//放置数据
components //绑定其他组件
template //设置模板
props //往模板template传值
methods// 业务逻辑,js方法
computed//计算属性,依赖数据改变时才执行
watch //监听数据变化,返回新值和旧值
extends//添加扩展,对象形式
mixins//添加扩展,可多个对象,数组形式
render //创建Virtual Dom

//属性的大致用法
export default {
	name:'xxx',     
	data:{
		dataSour:dataSource,
		url:'https://www.baidu.com',
		num:1,
		clother:"aaa"
	},	
	components:{
		ACom:AComponent
	},
	template:`<p>props传的值为{{a}}</p>`
	props:['a'],
	methods:{
		functionA:function(){
			console.log(this is the funciton A);
		}
		functionB:function(a,$event){
			console.log($event);
		}	
	},
	computed:{
		newdataSour:function(){
			return this.dataSour
		}
	},
	extends:{
		updated:function(){
            console.log('updated'+this.num);
        }
	},
	mixins:[addConsole,addConsoleTwo],
	watch:{
		tem:function(newVal, oldVal) {
			if(newVal == 26){
				this.clother = "aaa";
			}else if(newVal ==26 && newVal >=10 ){
				this.clother = "bbb";
			}else{
				this.clother = "ccc";
			} 
		}
	}	
}

</script>

有以下生命周期方法

初始化显示
*beforeCreate()
*created()
*beforeMount()
*mounted()
更新状态:this.xxx=value
*beforeUpdate()
*updated()
销毁 vue 实例:vm.$destory()
*beforeDestory()
*destoryed()

//方法的大致用法
export default {
	name:'xxx',     
	data:{
		dataSour:dataSource,
		url:'https://www.baidu.com',
		num:1,
		clother:"aaa"
	},	
	beforeCreate:function(){
   		 console.log('1-beforeCreate 初始化之后');
	},
	created:function(){
	    console.log('2-created 创建完成');
	},
	beforeMount:function(){
	    console.log('3-beforeMount 挂载之前');
	},
	mounted:function(){
	    console.log('4-mounted 挂载后');
	},
	beforeUpdate:function(){
	    console.log('5-beforeUpdate 数据更新前');
	},
	updated:function(){
	    console.log('6-updated 被更新后');
	},
	activated:function(){
	    console.log('7-activated');
	},
	deactivated:function(){
	    console.log('8-deactivated');
	},
	beforeDestroy:function(){
	    console.log('9-beforeDestroy 销毁之前');
	},
	destroyed:function(){
	    console.log('10-destroyed 销毁之后')
	}
}

待续

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WARN "css.modules" option in vue.config.js is deprecated now, please use "css.requireModuleExtension" instead. INFO Starting development server... 98% after emitting CopyPlugin WARNING Compiled with 17 warnings 09:43:57 warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'computed' was not found in 'vue' warning in ./src/router/index.js "export 'default' (imported as 'VueRouter') was not found in 'vue-router' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'defineComponent' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'getCurrentInstance' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'h' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'inject' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'nextTick' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onActivated' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onDeactivated' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onUnmounted' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'provide' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'reactive' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'ref' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'shallowRef' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'unref' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'watch' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'watchEffect' was not found in 'vue'这个报错因为什么
06-09

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值