Vue学习之从入门到神经(万字长文 建议收藏)(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

@RequestMapping(“/user”)

@Controller

@ResponseBody

public class UserController {

@Autowired

private IUserService userService;

@RequestMapping(value=“/findAll.do”)

public List findAll() {

return userService.findAll();

}

@RequestMapping(value=“/findById.do”)

public User findById(Integer id) {

return userService.findById(id);

}

@RequestMapping(value=“/update.do”)

public User update(@RequestBody User user) {

return userService.update(user);

}

}

7.3.3.Dao

public interface IUserDao {

@Select(“select * from user”)

public List findAll();

@Select(“select * from user where id=#{id}”)

User findById(Integer id);

@Update("update user set username=#{username},password=#{password},sex=#{sex},age=#

{age},email=#{email} where id=#{id}")

void update(User user);

}

7.4.客户端


7.4.1.user.html页面

原因种种 页面代码暂时提供不了 思路大概就是这些 嘻嘻~

7.4.2.user.js

var vue = new Vue({

el: “#app”,

data: {

user: {id:“”,username:“aaa”,password:“”,age:“”,sex:“”,email:“”},

userList: []

},

methods: {

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip1024c (备注前端)
img

结尾

正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。

以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。

前端学习书籍导图-1

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
img

= new Vue({

el: “#app”,

data: {

user: {id:“”,username:“aaa”,password:“”,age:“”,sex:“”,email:“”},

userList: []

},

methods: {

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-woR5Qiy1-1712449432841)]
[外链图片转存中…(img-RKWNm3ml-1712449432842)]
[外链图片转存中…(img-TwSz08Fz-1712449432842)]
[外链图片转存中…(img-JbhrgZUH-1712449432843)]
[外链图片转存中…(img-2evpxKUk-1712449432843)]
[外链图片转存中…(img-m87HmrAm-1712449432843)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-ZtgcFRMV-1712449432844)]

结尾

正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。

以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。

[外链图片转存中…(img-QXQYPeG9-1712449432844)]

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-jr4dJLqQ-1712449432844)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值