当前位置: 首页 > Web前端 > HTML

【可视化】Vue基础

时间:2023-04-02 21:21:44 HTML

来源|达达前端小酒馆Vue介绍Vue框架,框架的作者,有雨溪,组件化,快速开发的特点。生命周期beforeCreate:组件刚刚创建created:组件创建并生成beforeMount:挂载前mounted:挂载后成熟beforeDestory:组件销毁前调用destroyed:组件销毁后调用oldinstallation:全局安装:vue-clinpminstall--globalvue-cli根据webpack模板新建项目vueinitwebpackmy-project安装依赖:cdmy-projectnpminstallnpmrundev@代表src目录:importVuefrom'vue'importRouterfrom'vue-router'importHellofrom'@/components/Hello'Vue.use(Router)exportdefaultnewRouter({routes:[{path:'/',name:'hello',component:Hello}]})生命周期call:beforeCreatecreatedbeforeMountmountedinstancelifecyclehookssuchascreatedhooknewVue({data:{a:1},created:function(){//`this`指向vm实例console.log('ais:'+this.a)}})//=>"ais:1"生命周期钩子的this上下文指向调用它的Vue实例。生命周期图选项数据:data、computed、methods定义全局组件变量:computed:{//内部函数msg(){returnthis.a*2;}}@click="say('hi')"methods:{say(){}}模板语法数据,直接嵌入js代码、指令、v-html、v-on、v-bind等,计算属性,模板中的过滤器。

{{number+1}}
v-on:click=""简写@click{{msg.split('').reverse().join('')}}this.msg.split('').reverse().join('');类与样式绑定class1
data(){return{isActive:true,hasError:false}}
原始的写法:dada
style
style2style3条件命令v-if指令v-ifv-elsev-ifv-else-ifv-elsedadaABCDv-show和v-if同义列表渲染v-for命令v-for="项目中的项目”数组v-for="(item,index)initems"arrayv-for="(value,key)inobject"object{{index}}-{{item.消息}}{{item.message}}{{key}}-{{value}}事件handlerv-on指令,缩写为@v-on:click或@click

{{counter}}

自定义组件组件是写在components文件夹,components基本元素,props,$emit等,通过import导入自定义组件<模板>

{{time}}

Vue中的Dom操作this.$refs.head.innerHTML='dada';过渡有效过渡transition样式写过渡dadapv-if="show">dada

路径由vue-routerrouter-linknpminstall引入vue-router包dadadadatoUrl(){this.$router.push({path:'dada'})}状态管理npminstall引入vuex包的全局状态管理,所有页面共享数据设置数据:this.$store.dispatch("dada",1222);获取数据:this.$store.state.numexportdefaultnewVuex.Store({state:{count:0,num:1},mutations:{increment(state,num){state.count++state.num=num}},动作:{inc({commit},obj){commit('increment',obj)}}})this.$store.dispatch('inc',111);slotcommonlanguagecomponentcallimportslotsfrom'@/components/slot.vue'vue-resource请求npminstall引入vue-资源包this.$http.get('/daurl')this.$http.post('/daurl',{foo:'bar'})this.$http.get('/dadaurl').then(response=>{console.log(response.body);},response=>{//错误});}}这个。$http.post('/daurl',{foo:'bar'}).then(response=>{console.log(response.body);},response=>{//错误回调});手机组件库MintUI地址:http://mint-ui.github.io/docs...??别忘了留下你的足迹【点赞+收藏+评论】作者信息:【作者】:Jeskson【原创】]:达达前端小酒馆【福利】:公众号回复“信息”,送自学资料大礼包(进群分享,想要什么就说,看我有没有)!【转载说明】:转载请注明出处,谢谢合作!~大前端开发,定位前端开发技术栈博客,PHP背景知识点,web全栈技术领域,数据结构与算法,网络原理等以通俗易懂的方式呈现给小伙伴方式。感谢您的支持,感谢您的厚爱!!!如本账号内容有问题(例如:涉及版权或其他问题),请及时联系我们进行整改,我们会尽快处理。请喜欢它!因为您的认可/鼓励是我写作最大的动力!欢迎来到达达的CSDN!这是一个有品质有态度的博客