VUE 知识点汇总:

2022-10-10  本文已影响0人  饼子_5a37

已安装好node.js 16.14.2

一、项目脚手架

npm install -g @vue/cli 或  yarn add -g @vue/cli
vue create 项目的名字(尽量用英文)
npm run serve
> 安装新的软件包,使用npm i 依赖包的名字 或 yarn add 依赖包的名字

二、VUE相关概念

1665900958510.png
<!-- 具名插槽 -->
<BaseLayout>
 <template v-slot:header>
   Header content
 </template>

 <template v-slot:default>
   Default slot content
 </template>

 <template v-slot:footer>
   Footer content
 </template>
</BaseLayout>

<!-- 接收 prop 的具名插槽 -->
<InfiniteScroll>
 <template v-slot:item="slotProps">
   <div class="item">
     {{ slotProps.item.text }}
   </div>
 </template>
</InfiniteScroll>
<template>
  <div class="about">
    <el-form label-position="left" label-width="100px" style="max-width: 460px">
      <el-form-item label="用户名">
        <el-input v-model="formObj.username" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="formObj.password" />
      </el-form-item>
      <el-form-item>
        <!-- 使用动态跳转方式 -->
        <el-button type="primary" @click="submitForm()">立即登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "LoginView",
  data() {
    return {
      // 在 eslint 中的标准的对象,k-value 中的 value通常需要使用 单引号
      formObj: {
        username: "",
        password: "",
      },
    };
  },
}

在template中不用写this

这里面不能写耗时的一些代码,必须有返回值

computed: {
    orderStatData2() {
        return this.$store.state.home.orderStatArr;
    },
},
export default {
   data() {
       return {
           question: '',
           answer: 'Questions usually contain a question mark. ;-)'
       }
   },
   watch: {
       question(newQuestion,oldQuestion) {
           if(newQuestion,include('?')){
               this.getAnswer()
           }
       }
   }
}
export default {    props: {        
title:String,                
likes:Number,    }}
export const score = {
    //这里和组件中的export default{}中的属性平级关系
  methods: {
    //弹出分数
    alentScore(student, score1) {
      alert(student + "的成绩是:" + score1);
    },
  },
};

局部混入的使用

1665902796205.png
<Demo @atguigu="test"/>或<Demo v-on:atguigu="test"/>

第三种:跨组件(2.0之前,3.0之后this.$on()取消了)

this.on() 在需要的组件中

第四种:插槽

默认插槽、具名插槽、作用域插槽

1665902913820.png 1665902956681.png

作用域插槽:商品列表(elementUI中的table组件)

数据在子组件中,但是自己不能决定结构,需要将数据传递给父组件,父组件决定结构

三、路由(vue-router)

路由是前端框架定制化后的一种对界面跳转的新叫法

路由懒加载,延迟加载 import中的值是 路径地址 component: () => import("../layout/BaseLayout.vue")

1665903203963.png

第一种:使用path中的占位符号(定义的方式 :id,id相当于形参)

多用于嵌套路由

1665903298831.png

跳转的页面接收:

1665903337913.png

第二种:push方法

多用于单页面间的跳转

常规用法

1665903376496.png

传递参数的用法

1665903417941.png

小程序使用的 uni.navigateTo:跳转单页面 uni.switchTab:跳转到tab导航页面

//to:要跳转的导航地址  from:当前页面  next:执行跳转页面的方法 
router.beforeEach((to,from,next) =>{
    //判断是否登录过了,如果是,跳转到to传入的页面地址,反之,拦截页面跳转,还停留在登陆界面
    if(to.name !== 'login' && !isAuthenticater)
    next({name:'login'})
    else next()
})

全局的后置守卫

1665903476286.png

使用$route.meta 获取到元信息

1665903509586.png

用到的组件库

Element-ui 2.2.17

uView 2.0

上一篇 下一篇

猜你喜欢

热点阅读