Web前端最全Vue学习之从入门到神经(万字长文 建议收藏)(1),正在准备面试英语

ajax

1)ajax请求的原理/ 手写一个ajax请求?
2)readyState?
3)ajax异步与同步的区别?
4)ajax传递中文用什么方法?

ajax.PNG

前12.PNG

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

6.循环遍历(v-for)


6.1.遍历数组

语法

v-for=“item in items”

v-for=“(item,index) in items”

items:要迭代的数组

item:存储数组元素的变量名

index:迭代到的当前元素索引,从0开始。

代码

    • {{index}}–{{user.name}}–{{user.age}}–{{user.gender}}

      6.2.遍历对象

      语法

      v-for=“value in object”

      v-for=“(value,key) in object”

      v-for=“(value,key,index) in object”

      value,对象的值

      key, 对象的键

      index, 索引,从0开始

      代码

      • {{index}}–{{key}}–{{value}}

        6.3.key

        概述:

        ​ :key 一般配合v-for一起使用. 用来在特定情况下, 保证被遍历的数组中的元素的顺序.

        案例:

        <button @click=“add”>添加

        • {{name}}

          效果:

          在这里插入图片描述

          解决方案:

          <button @click=“add”>添加

          • {{name}}

            7.判断语法(v-if和v-show)


            概述:

            v-if与v-show可以根据条件的结果,来决定是否显示指定内容.

            ​ v-if: 条件不满足时, 元素不会存在.

            ​ v-show: 条件不满足时, 元素不会显示(但仍然存在).

            案例

            <button @click=“show = !show”>点我

            Hello v-if.

            Hello v-show.

            8.显示数据(v-bind)


            概述:

            v-bind的作用和插值表达式差不多, 只不过, v-bind主要用于动态设置标签的属性值

            语法

            <标签名 v-bind:标签属性名=“vue实例中的数据属性名”/>

            <标签名 :标签属性名=“vue实例中的数据属性名”/>

            案例

            9.Vue页面跳转(两种方法)


            9.1.方法一(标签实现)

            <router-link :to=“{name: ‘bookshelf’, params: { entityId: this.entityId } }”

            :class=“{‘flex-item-1’:‘flex-item-1’,cur:tabs[0].isShow}” href=“javascript:”>

            书 架

            9.1.方法二(this.$router.push()实现)

            当this.$router.push()只有一个参数时 默认为跳转地址 最多可传两个参数 第二个参数为地址参数

            <a @click=“toIndex” :class=“{‘flex-item-1’:‘flex-item-1’,cur:tabs[2].isShow}” href=“javascript:”>

            首 页

            toIndex: function(){

            this.$router.push(“/?entityId=”+ localStorage.getItem(“entityId”));

            }

            三、Vue其他语法

            =====================================================================

            3.1.计算属性


            概述:计算属性就是一个提前定义好的方法, 该方法可以看作是一个特殊的值, 可以在插值表达式中使用.

            语法

            var app = new Vue({

            el:“#app”,

            //计算属性必须放在Vue的computed中

            computed:{

            //定义计算属性

            属性名(){

            return “返回值”;

            }

            }

            });

            案例:

            {{birth}}

            3.2.watch监控


            概述

            ​ watch可以监听简单属性值及其对象中属性值的变化.

            ​ watch类似于onchange事件,可以在属性值修改的时候,执行某些操作.

            语法

            var app = new Vue({

            el:“#app”,

            data:{

            message:“白大锅”,

            person:{“name”:“heima”, “age”:13}

            },

            //watch监听

            watch:{

            //监听message属性值,newValue代表新值,oldValue代表旧值

            message(newValue, oldValue){

            console.log(“新值:” + newValue + “;旧值:” + oldValue);

            },

            //监控person对象的值,对象的监控只能获取新值

            person: {

            //开启深度监控;监控对象中的属性值变化

            deep: true,

            //获取到对象的最新属性数据(obj代表新对象)

            handler(obj){

            console.log("name = " + obj.name + “; age=” + obj.age);

            }

            }

            }

            });

            四、Vue组件

            ===================================================================

            4.1.基本使用


            概述:

            组件, 类似于模版, 模块. 在项目需要重用某个模块(头部、尾部、新闻。。。)的时候,可以将模块抽取成组件,其它页面中注册组件并引用。

            案例:

            注意:

            1. 组件的模版中, 只能书写一个跟标签
            1. 组件的定义必须放在Vue创建对象之前, 否则报错

            4.2.父组件向子组件通信


            概述:

            子组件无法直接使用父组件中的数据, 如果需要使用, 则必须由父组件把数据传递给子组件才可以.

            本质: 让子组件中的属性与父组件中的属性进行关联绑定, 然后子组件使用该属性, 这样才能做到数据传递

            意义:

            可以把父组件中的数据, 更新传递到子组件

            示例:

            4.3.子组件向父组件通信


            概述:

            子组件无法直接给父组件传递数据. 也无法操作父组件中的数据, 更无法调用父组件中的方法.

            所以, 所谓的子组件向父组件通讯, 其实就是想办法让子组件调用父组件的方法. 进而响应到父组件中的数据.

            意义:

            子组件可以调用父组件中的方法

            示例:

            父组件中:app_num={{app_num}}

            <counter @aaa=“add” @bbb=“rem” :counter_num=“app_num”>

            五、axios异步请求

            =======================================================================

            5.1 axios概述


            概述:

            axios是一个基于 promise 的 HTTP 库, 主要用于:发送异步请求获取数据

            常见的方法:

            ​ axios(config)

            ​ axios.get(url, [config])

            ​ axios.post(url, [data])

            发送数据config常用参数:

            {

            url: ‘请求的服务器’,

            method: ‘请求方式’, // 默认是 get

            // GET请求参数

            params: {

            参数名: 参数值

            },

            // POST请求参数, 如果使用axios.post,则参数在url之后直接书写,不需要该位置传递参数

            data: {

            参数名: 参数值

            },

            // 响应数据格式,默认json

            responseType: ‘json’

            }

            响应数据常用参数:

            {

            data: {}, //真正的响应数据(响应体)

            status: 200, //响应状态码

            statusText: ‘OK’, //响应状态描述

            headers: {}, //响应头

            config: {} //其他配置信息

            }

            5.2.Get请求


            var app = new Vue({

            el: “#app”,

            data: {

            user: {}

            },

            //当页面加载完毕后

            created() {

            //发送GET请求axios.get(“请求路径”,{ config });

            axios.get(“请求路径”,{

            //get请求参数

            params: {

            name:“zhangsan”,

            age:23

            },

            //响应数据格式为"json"

            responseType: ‘json’

            }).then(res => {

            //打印响应数据

            console.log(res);

            //把响应数据赋值给Vue中的user属性

            app.user = res.data;

            }).catch(err => {

            //打印响应数据(错误信息)

            console.log(err);

            });

            }

            });

            5.3.Post请求


            var app = new Vue({

            el: “#app”,

            data: {

            user: {}

            },

            //当页面加载完毕后

            created() {

            //发送POST请求axios.post(“请求路径”,{ 参数 });

            axios.post(“请求路径”,{

            name:“zhangsan”,

            age:23

            }).then(res => {

            console.log(res);

            app.user = res.data;

            }).catch(err => {

            console.log(err);

            });

            }

            });

            5.4.跨域请求


            跨域请求:在前端js中如果发送异步请求的话,请求的地址与当前服务器的ip或者端口号不同都是跨域请求.

            跨域请求需要在服务提供方, 开启允许跨域请求

            在这里插入图片描述

            六、VueJs Ajax

            ========================================================================

            6.1.vue-resource


            vue-resource是Vue.js的插件提供了使用XMLHttpRequest或JSONP进行Web请求和处理响应的服务。 当vue更新

            到2.0之后,作者就宣告不再对vue-resource更新,而是推荐的axios,在这里大家了解一下vue-resource就可以。

            vue-resource的github: https://github.com/pagekit/vue-resource

            6.2.axios


            Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中

            axios的github:https://github.com/axios/axios

            6.2.1.引入axios

            首先就是引入axios,如果你使用es6,只需要安装axios模块之后

            import axios from ‘axios’;

            //安装方法

            npm install axios

            //或

            bower install axios

            当然也可以用script引入

            6.2.2.get请求

            //通过给定的ID来发送请求

            axios.get(‘/user?ID=12345’)

            .then(function(response){

            console.log(response);

            }).catch(function(err){

            console.log(err);

            });

            //以上请求也可以通过这种方式来发送

            axios.get(‘/user’,{

            params:{

            ID:12345

            }

            }).then(function(response){

            console.log(response);

            }).catch(function(err){

            console.log(err);

            });

            6.2.3.post请求

            axios.post(‘/user’,{

            firstName:‘Fred’,

            lastName:‘Flintstone’

            })

            .then(function(res){

            console.log(res);

            })

            .catch(function(err){

            console.log(err);

            });

            为方便起见,为所有支持的请求方法提供了别名

            axios.request(config)

            axios.get(url[, config])

            axios.delete(url[, config])

            axios.head(url[, config])

            axios.post(url[, data[, config]])

            axios.put(url[, data[, config]])

            axios.patch(url[, data[, config]])

            七、综合案例

            ==================================================================

            7.1.需求


            完成用户的查询与修改操作

            7.2. 数据库设计与表结构


            CREATE DATABASE vuejsdemo;

            USE vuejsdemo;

            CREATE TABLE USER(

            id INT PRIMARY KEY AUTO_INCREMENT,

            age INT,

            username VARCHAR(20),

            PASSWORD VARCHAR(50),

            email VARCHAR(50),

            sex VARCHAR(20)

            )

            User类

            public class User {

            private Integer id;

            private String username;

            private String password;

            private String sex;

            private int age;

            private String email;

            省略getter/setter

            7.3.服务器端


            7.3.1.配置文件

            web.xml

            <?xml version="1.0" encoding="UTF-8"?>

            <web-app xmlns=“http://xmlns.jcp.org/xml/ns/javaee”

            xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

            xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee

            http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

            version=“3.1”

            metadata-complete=“true”>

            contextConfigLocation

            classpath:applicationContext.xml

            org.springframework.web.context.ContextLoaderListener

            springmvcDispatcherServlet

            org.springframework.web.servlet.DispatcherServlet

            contextConfigLocation

            classpath:springmvc.xml

            1

            springmvcDispatcherServlet

            *.do

            CharacterEncodingFilter

            org.springframework.web.filter.CharacterEncodingFilter

            encoding

            UTF-8

            forceEncoding

            true

            CharacterEncodingFilter

            /*

            index.html

            index.htm

            index.jsp

            default.html

            default.htm

            default.jsp

            springmvc.xml

            <?xml version="1.0" encoding="UTF-8"?>

            <beans xmlns=“http://www.springframework.org/schema/beans”

            xmlns:mvc=“http://www.springframework.org/schema/mvc”

            xmlns:context=“http://www.springframework.org/schema/context”

            xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

            xsi:schemaLocation="http://www.springframework.org/schema/beans

            http://www.springframework.org/schema/beans/spring-beans.xsd

            http://www.springframework.org/schema/mvc

            http://www.springframework.org/schema/mvc/spring-mvc.xsd

            http://www.springframework.org/schema/context

            http://www.springframework.org/schema/context/spring-context.xsd">

            <context:component-scan base-package=“com.itheima”>

            <context:include-filter type=“annotation”

            expression=“org.springframework.stereotype.Controller”/>

            </context:component-scan>

            mvc:annotation-driven</mvc:annotation-driven>

            applicationContext.xml

            <?xml version="1.0" encoding="UTF-8"?>

            <beans xmlns=“http://www.springframework.org/schema/beans”

            xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

            xmlns:aop=“http://www.springframework.org/schema/aop”

            xmlns:tx=“http://www.springframework.org/schema/tx”

            xmlns:context=“http://www.springframework.org/schema/context”

            xsi:schemaLocation="http://www.springframework.org/schema/beans

            http://www.springframework.org/schema/beans/spring-beans.xsd

            http://www.springframework.org/schema/tx

            http://www.springframework.org/schema/tx/spring-tx.xsd

            http://www.springframework.org/schema/aop

            http://www.springframework.org/schema/aop/spring-aop.xsd

            http://www.springframework.org/schema/context

            http://www.springframework.org/schema/context/spring-context.xsd">

            <context:component-scan base-package=“com.itheima”>

            <context:exclude-filter type=“annotation”

            expression=“org.springframework.stereotype.Controller”/>

            </context:component-scan>

            <context:property-placeholder location=“classpath:db.properties”/>

            tx:annotation-driven/

            <bean id=“transactionManager”

            class=“org.springframework.jdbc.datasource.DataSourceTransactionManager”>

            db.properties

            jdbc.driver=com.mysql.jdbc.Driver

            jdbc.url=jdbc:mysql://localhost:3306/vuejsDemo

            jdbc.username=root

            jdbc.password=root

            7.3.2.Controller

            跳槽是每个人的职业生涯中都要经历的过程,不论你是搜索到的这篇文章还是无意中浏览到的这篇文章,希望你没有白白浪费停留在这里的时间,能给你接下来或者以后的笔试面试带来一些帮助。

            也许是互联网未来10年中最好的一年。WINTER IS COMING。但是如果你不真正的自己去尝试尝试,你永远不知道市面上的行情如何。这次找工作下来,我自身感觉市场并没有那么可怕,也拿到了几个大厂的offer。在此进行一个总结,给自己,也希望能帮助到需要的同学。

            面试准备

            开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

            面试准备根据每个人掌握的知识不同,准备的时间也不一样。现在对于前端岗位,以前也许不是很重视算法这块,但是现在很多公司也都会考。建议大家平时有空的时候多刷刷leetcode。算法的准备时间比较长,是一个长期的过程。需要在掌握了大部分前端基础知识的情况下,再有针对性的去复习算法。面试的时候算法能做出来肯定加分,但做不出来也不会一票否决,面试官也会给你提供一些思路。

            配置 MyBatis 的 Session 工厂 -->

            tx:annotation-driven/

            <bean id=“transactionManager”

            class=“org.springframework.jdbc.datasource.DataSourceTransactionManager”>

            db.properties

            jdbc.driver=com.mysql.jdbc.Driver

            jdbc.url=jdbc:mysql://localhost:3306/vuejsDemo

            jdbc.username=root

            jdbc.password=root

            7.3.2.Controller

            跳槽是每个人的职业生涯中都要经历的过程,不论你是搜索到的这篇文章还是无意中浏览到的这篇文章,希望你没有白白浪费停留在这里的时间,能给你接下来或者以后的笔试面试带来一些帮助。

            也许是互联网未来10年中最好的一年。WINTER IS COMING。但是如果你不真正的自己去尝试尝试,你永远不知道市面上的行情如何。这次找工作下来,我自身感觉市场并没有那么可怕,也拿到了几个大厂的offer。在此进行一个总结,给自己,也希望能帮助到需要的同学。

            面试准备

            开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

            面试准备根据每个人掌握的知识不同,准备的时间也不一样。现在对于前端岗位,以前也许不是很重视算法这块,但是现在很多公司也都会考。建议大家平时有空的时候多刷刷leetcode。算法的准备时间比较长,是一个长期的过程。需要在掌握了大部分前端基础知识的情况下,再有针对性的去复习算法。面试的时候算法能做出来肯定加分,但做不出来也不会一票否决,面试官也会给你提供一些思路。

          评论
          添加红包

          请填写红包祝福语或标题

          红包个数最小为10个

          红包金额最低5元

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

          抵扣说明:

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

          余额充值