Vue.js中的8種組件間的通信方式;3個組件實例是前6種通信的實例,組件直接復制粘貼即可看到運行結果

文章目錄

        • 一、$children / $parent
        • 二、props / $emit
        • 三、eventBus
        • 四、ref
        • 五、provide / reject
        • 六、$attrs / $listeners
        • 七、localStorage / sessionStorage
        • 八、Vuex

實例以element ui為例。例子從上往下逐漸變復雜(后面例子沒有刪前面的無用代碼,有時間重新整理一下!)

一、$children / $parent

在這里插入圖片描述

  • 拿到 $children / $parent 即可訪問子 / 父 組件的所有變量和方法。
  • 官方說 $children / $parent 僅作為應急的通信方法,其中一個原因就是 $children / $parent僅代表的是根組件下的第一個子/父vue組件(普通html標簽不含有vue實例,不包含在內),當位置變化或者之間需要增加新的組件,對應的指向就變了,如以下例子。
  • 一般用在組件簡單且不易改變的情形,單獨把子組件放在根組件的下一級。
  • 使用實例(復制粘貼即可跑起來看效果):
// 子組件
// 1.創建子組件
<template><div><!-- 注意:template中沒有this,這里沒有this,即不用this.parentMsg -->我是子組件,父組件的數據:{{parentMsg}}</div>
</template><script>
export default {data() {return {msg: "children",parentMsg:""};},mounted(){console.log(this.$parent)this.parentMsg = this.$parent.msg}
};
</script><style scoped>
</style>
// 父組件
<template><!-- 4.使用 --><div><div class="main">我是父組件,子組件的數據:{{childrenMsg}}</div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><p-com></p-com></div>
</template><script>
// 2.引入
import pCom from "./pCom";export default {components: { pCom }, // 3.掛載data() {return {msg: "parent",childrenMsg: ""};},mounted() {console.log(this.$children)this.childrenMsg = this.$children[0].msg;}
};
</script><style scoped>
</style>

兩個vue文件放在同一目錄下即可運行。
中間需要間插入el組件時,父子關系變為子孫,獲取數據失敗:

// 父組件模板改為此
<template><!-- 4.使用 --><div><div class="main">我是父組件,子組件的數據:{{childrenMsg}}</div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><el-card><p-com></p-com></el-card></div>
</template>

然而插入非element組件(即html標簽),則父子關系不變:

// 父組件模板改為此
<template><!-- 4.使用 --><div><div class="main">我是父組件,子組件的數據:{{childrenMsg}}</div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><div><p-com></p-com></div></div>
</template>

二、props / $emit

官方推薦的父子關系通信方式,不用在乎層級關系,而且沒有多余數據傳輸,父組件給什么,子組件就拿什么、用什么。(原理也是監聽和廣播,后第三種方式一樣,只不過這是局部的,別忘了@是v-on的省略)。props應該也可以放函數地址然后子組件調用,如果可以的話也可以替代emit(待測)。
父組件:

<template><!-- 4.使用 --><div>父組件:<div class="main">我是父組件,我自己拿的子組件數據:{{childrenMsg}}<el-button type="text" @click="alertBox(true)">點我出彈框</el-button><br />子組件主動給我更新的數據:{{childrenMsg2}}</div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><br />子組件:<p-com:parentMsg2="msg"memo="這是爸爸傳給你的字符串"@alertBox="flag=>{alertBox(flag)}"@setParentMsg="msg=>{setMsg(msg)}"></p-com></div>
</template><script>
// 2.引入
import pCom from "./pCom";export default {components: { pCom }, // 3.掛載data() {return {msg: "parent",childrenMsg: "",childrenMsg2: ""};},methods: {alertBox(flag) {alert(`調用了${flag ? "自己" : "爸爸"}的彈框`);},setMsg(msg) {this.childrenMsg2 = msg;}},mounted() {console.log(this.$children);this.childrenMsg = this.$children[1].msg;}
};
</script><style scoped>
</style>

子組件:

<template><div><!-- 注意:template中沒有this,這里沒有this,即不用this.parentMsg -->我是子組件,我自己拿的父組件數據:{{parentMsg}}<br />爸爸用props傳給我的信息:{{parentMsg2}}(備注:{{memo}}<el-button type="text" @click="useParentMethods">點我出彈框,并且修改爸爸的數據</el-button></div>
</template><script>
export default {props: ["parentMsg2", "memo"],data() {return {msg: "children",parentMsg: ""};},methods: {useParentMethods() {this.$emit("alertBox", false);this.$emit("setParentMsg", `看你還囂張! ${Date().split(' ')[4]}`);}},mounted() {console.log(this.$parent);this.parentMsg = this.$parent.msg;}
};
</script><style scoped>
</style>

三、eventBus

監聽和廣播:
優點:使用簡單,導入即用。
缺點:閱讀性差,因為你只能打印出這個bus(vue實例),看到所有的監聽事件,但并不知道事件誰用了,在哪用的,用來干什么,所以僅適合小規模開發,非父子組件交互較少場景,僅用來處理非父子組件間的通信。
使用:
1.封裝一個bus
model下新建eventBus.js(一般是這個目錄)
在這里插入圖片描述
內容

import Vue from 'vue'var EmitData =  new Vue();
export default EmitData; // 暴露一個vue實例,統一監聽、廣播所有事件

2.父組件導入并且監聽(非父子組件也如此)

<template><!-- 4.使用 --><div>父組件:<div class="main">我是父組件,我自己拿的子組件數據:{{childrenMsg}}<el-button type="text" @click="alertBox(true)">點我出彈框</el-button><br />子組件主動給我更新的數據:{{childrenMsg2}}<div>廣播更新時間:{{time}}</div></div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><br />子組件:<p-com:parentMsg2="msg"memo="這是爸爸傳給你的字符串"@alertBox="flag=>{alertBox(flag)}"@setParentMsg="msg=>{setMsg(msg)}"></p-com></div>
</template><script>
// 2.引入
import pCom from "./pCom";
import eventBus from "@/model/eventBus.js";export default {components: { pCom }, // 3.掛載data() {return {msg: "parent",childrenMsg: "",childrenMsg2: "",time: ""};},methods: {alertBox(flag) {alert(`調用了${flag ? "自己" : "爸爸"}的彈框`);},setMsg(msg) {this.childrenMsg2 = msg;}},mounted() {console.log(this.$children);this.childrenMsg = this.$children[1].msg;eventBus.$on("updateTime", time => {this.time = time;});}
};
</script><style scoped>
</style>

3.子組件導入并且廣播(觸發事件)(非父子組件也如此)

<template><div><!-- 注意:template中沒有this,這里沒有this,即不用this.parentMsg -->我是子組件,我自己拿的父組件數據:{{parentMsg}}<br />爸爸用props傳給我的信息:{{parentMsg2}}(備注:{{memo}}<el-button type="text" @click="useParentMethods">點我出彈框,并且修改爸爸的數據</el-button><el-button @click="updateParentTime">點我更新時間</el-button></div>
</template><script>
import eventBus from "@/model/eventBus.js";export default {props: ["parentMsg2", "memo"],data() {return {msg: "children",parentMsg: ""};},methods: {useParentMethods() {this.$emit("alertBox", false);this.$emit("setParentMsg", `看你還囂張! ${Date().split(' ')[4]}`);},updateParentTime(){eventBus.$emit("updateTime",Date().split(' ')[4])}},mounted() {console.log(this.$parent);this.parentMsg = this.$parent.msg;}
};
</script><style scoped>
</style>

移除監聽:

eventBus.$off('updateTime', {}) 

四、ref

如果在普通的 DOM 元素上使用ref,引用指向的就是 DOM 元素;如果用在element組件上,引用就指向組件vue實例,可以通過實例直接調用組件的方法、數據或 DOM 元素。
所以ref是單向的,父操作子的數據和方法。
使用:
給子組件注入ref=“xx”,之后xx就是這個子組件的實例了(在this.$refs.xx調用時要注意他是最后加載的,一般為了確保加載完成可以使用setTimeout或者this.$nextTick(()=>{this.$refs.xx}))
子組件不用變,父組件增加ref

<template><!-- 4.使用 --><div>父組件:<div class="main">我是父組件,我自己拿的子組件數據:{{childrenMsg}}<el-button type="text" @click="alertBox(true)">點我出彈框</el-button><br />子組件主動給我更新的數據:{{childrenMsg2}}<div>廣播更新時間:{{time}}</div><el-button @click="getChild()">點我使用refs拿子組件數據和方法</el-button></div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><br />子組件:<p-com:parentMsg2="msg"memo="這是爸爸傳給你的字符串"@alertBox="flag=>{alertBox(flag)}"@setParentMsg="msg=>{setMsg(msg)}"ref="pCom"></p-com></div>
</template><script>
// 2.引入
import pCom from "./pCom";
import eventBus from "@/model/eventBus.js";export default {components: { pCom }, // 3.掛載data() {return {msg: "parent",childrenMsg: "",childrenMsg2: "",time: ""};},methods: {alertBox(flag) {alert(`調用了${flag ? "自己" : "爸爸"}的彈框`);},setMsg(msg) {this.childrenMsg2 = msg;},getChild(){alert("子組件msg:"+this.$refs.pCom.msg+" ;并且更新自己的時間")this.$refs.pCom.updateParentTime()}},mounted() {console.log(this.$children);this.childrenMsg = this.$children[1].msg;eventBus.$on("updateTime", time => {this.time = time;});}
};
</script><style scoped>
</style>

五、provide / reject

provide/ inject 是vue2.2.0新增的api,在組件多層嵌套的時候,根組件只要通過provide來提供變量, 然后任意子組件(孫組件、重孫等等)中通過inject來注入變量(注入this中)即可拿到根組件數據、方法。不局限于只能從當前父組件的props屬性中獲取數據、方法。由此可知,provide / reject是單向的,只提供子孫等組件獲取根組件數據、方法。
父組件:

<template><!-- 4.使用 --><div>父組件:<div class="main">我是父組件,我自己拿的子組件數據:{{childrenMsg}}<el-button type="text" @click="alertBox(true)">點我出彈框</el-button><br />子組件主動給我更新的數據:{{childrenMsg2}}<div>廣播更新時間:{{time}}</div><el-button @click="getChild()">點我使用refs拿子組件數據和方法</el-button></div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><br />子組件:<p-com:parentMsg2="msg"memo="這是爸爸傳給你的字符串"@alertBox="flag=>{alertBox(flag)}"@setParentMsg="msg=>{setMsg(msg)}"ref="pCom"></p-com></div>
</template><script>
// 2.引入
import pCom from "./pCom";
import eventBus from "@/model/eventBus.js";export default {components: { pCom }, // 3.掛載data() {return {msg: "parent",childrenMsg: "",childrenMsg2: "",time: ""};},provide() {return {rootMsg: this.msg,rootAlertBox: this.alertBox};},methods: {alertBox(flag) {alert(`調用了${flag ? "自己" : "爸爸"}的彈框`);},setMsg(msg) {this.childrenMsg2 = msg;},getChild() {alert("子組件msg:" + this.$refs.pCom.msg + " ;并且更新自己的時間");this.$refs.pCom.updateParentTime();}},mounted() {console.log(this.$children);this.childrenMsg = this.$children[1].msg;eventBus.$on("updateTime", time => {this.time = time;});}
};
</script><style scoped>
</style>

子組件:

<template><div><!-- 注意:template中沒有this,這里沒有this,即不用this.parentMsg -->我是子組件,我自己拿的父組件數據:{{parentMsg}}<br />爸爸用props傳給我的信息:{{parentMsg2}}(備注:{{memo}}<el-button type="text" @click="useParentMethods">點我出彈框,并且修改爸爸的數據</el-button><el-button @click="updateParentTime">點我更新時間</el-button><el-button @click="userPJ()">點我看看provide / reject有沒有獲取到</el-button></div>
</template><script>
import eventBus from "@/model/eventBus.js";export default {props: ["parentMsg2", "memo"],data() {return {msg: "children",parentMsg: ""};},inject: {rootMsg: { default: "獲取根組件數據失敗" },rootAlertBox: {default: () => {return "獲取根組件函數失敗";}}},methods: {useParentMethods() {this.$emit("alertBox", false);this.$emit("setParentMsg", `看你還囂張! ${Date().split(" ")[4]}`);},updateParentTime() {eventBus.$emit("updateTime", Date().split(" ")[4]);},userPJ(){alert(this.rootMsg)this.rootAlertBox()}},mounted() {console.log(this.$parent);this.parentMsg = this.$parent.msg;}
};
</script><style scoped>
</style>

六、$attrs / $listeners

在vue2.4中,引入了$attrs 和$listeners , 新增了inheritAttrs 選項。

inheritAttrs:默認值true,繼承所有的父組件屬性(除props的特定綁定)作為普通的HTML特性應用在子組件的根元素上,如果你不希望組件的根元素繼承特性設置inheritAttrs: false,但是class屬性會繼承(簡單的說,inheritAttrs:true 繼承除props之外的所有屬性;inheritAttrs:false 只繼承class屬性)

$attrs–繼承所有的父組件屬性(除了prop傳遞的屬性、class 和 style ),一般用在子組件的子元素上,如第一個例子的

$listeners–屬性,它是一個對象,里面包含了作用在這個組件上的所有監聽器,你就可以配合 v-on="$listeners" 將所有的事件監聽器指向這個組件的某個特定的子元素。(相當于子組件繼承父組件的事件)
實現:

1.同級創建pCom的子組件ppCom

<template><el-button @click="runGrand()">點我調用 attrs / listeners</el-button>
</template>
<script>
export default {methods: {runGrand() {alert(this.$attrs.noProp);this.$listeners.alertBox(false);}},mounted() {console.log(this.$attrs);console.log(this.$listeners);}
};
</script>

2.pCom

<template><div><!-- 注意:template中沒有this,這里沒有this,即不用this.parentMsg -->我是子組件,我自己拿的父組件數據:{{parentMsg}}<br />爸爸用props傳給我的信息:{{parentMsg2}}(備注:{{memo}}<el-button type="text" @click="useParentMethods">點我出彈框,并且修改爸爸的數據</el-button><el-button @click="updateParentTime">點我更新時間</el-button><el-button @click="userPJ()">點我看看provide / reject有沒有獲取到</el-button><!-- attrs:在模板外需要用this.$attrs獲取,他包含了父組件的所有數據listeners:在模板外需要用this.$listeners獲取,他包含了父組件的所有事件(監聽)inheritAttrs - 默認true:inheritAttrs:true 子標簽繼承除props之外的所有特性;inheritAttrs:false 只繼承class屬性傳給下一級,注入到他的this--><br />pCom的子組件:<my-ppcom v-bind="$attrs" v-on="$listeners" ></my-ppcom></div>
</template><script>
import eventBus from "@/model/eventBus.js";
import ppCom from "./ppCom"export default {props: ["parentMsg2", "memo"],components:{"my-ppcom":ppCom},data() {return {msg: "children",parentMsg: ""};},inject: {rootMsg: { default: "獲取根組件數據失敗" },rootAlertBox: {default: () => {return "獲取根組件函數失敗";}}},methods: {useParentMethods() {this.$emit("alertBox", false);this.$emit("setParentMsg", `看你還囂張! ${Date().split(" ")[4]}`);},updateParentTime() {eventBus.$emit("updateTime", Date().split(" ")[4]);},userPJ(){alert(this.rootMsg)this.rootAlertBox()}},mounted() {console.log(this.$parent);this.parentMsg = this.$parent.msg;}
};
</script><style scoped>
</style>

3.父組件

<template><!-- 4.使用 --><div>父組件:<div class="main">我是父組件,我自己拿的子組件數據:{{childrenMsg}}<el-button type="text" @click="alertBox(true)">點我出彈框</el-button><br />子組件主動給我更新的數據:{{childrenMsg2}}<div>廣播更新時間:{{time}}</div><el-button @click="getChild()">點我使用refs拿子組件數據和方法</el-button></div><!-- 單獨放在根組件的下一級,保證層級關系不被影響 --><br />子組件:<p-com:parentMsg2="msg"memo="這是爸爸傳給你的字符串"@alertBox="flag=>{alertBox(flag)}"@setParentMsg="msg=>{setMsg(msg)}"ref="pCom"noProp="子組件不要prop接受我,這是給孫組件的字符串"></p-com></div>
</template><script>
// 2.引入
import pCom from "./pCom";
import eventBus from "@/model/eventBus.js";export default {components: { pCom }, // 3.掛載data() {return {msg: "parent",childrenMsg: "",childrenMsg2: "",time: ""};},provide() {return {rootMsg: this.msg,rootAlertBox: this.alertBox};},methods: {alertBox(flag) {alert(`調用了${flag ? "自己" : "爸爸"}的彈框`);},setMsg(msg) {this.childrenMsg2 = msg;},getChild() {alert("子組件msg:" + this.$refs.pCom.msg + " ;并且更新自己的時間");this.$refs.pCom.updateParentTime();}},mounted() {console.log(this.$children);this.childrenMsg = this.$children[1].msg;eventBus.$on("updateTime", time => {this.time = time;});}
};
</script><style scoped>
</style>

七、localStorage / sessionStorage

通信比較簡單,數據和狀態比較混亂,不太容易維護。
localStorage 將數據存入瀏覽器,關閉瀏覽器再次打開仍然存在,需要手動清除;
sessionStorage將數據存在對話框,關閉這個頁面就沒了。
他們的操作幾乎是一樣的,也都是js內置方法,也可以自己封裝以下(我的另一篇博客有封裝localStorage vue項目將token存在(vuex)store和localstorage中)。使用原生的話注意每次存入要JSON格式化,拿出要JSON解析。

localStorage 使用:

在任何地方使用 localStorage.setItem("k", JSON.stringify("v"))存入數據(方法-函數地址);
在任何地方使用 JSON.parse(localStorage.getItem("k")) 讀取數據(方法-函數地址);
任何地方包括vue實例以外,因為他是原生js。

八、Vuex

數據狀態管理器,適用于數據復雜、交互頻繁場景,選擇時要在不使用vue的困難和使用vuex的繁瑣中權衡,當然啦,不管用不用都應該拿個例子來學,見我的另一篇博客
Vue使用Vuex一步步封裝并使用store

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278701.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278701.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278701.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

不可思議的混合模式 background-blend-mode

本文接前文&#xff1a;不可思議的混合模式 mix-blend-mode 。由于 mix-blend-mode 這個屬性的強大&#xff0c;很多應用場景和動效的制作不斷完善和被發掘出來&#xff0c;遂另起一文繼續介紹一些使用 mix-blend-mode 制作的酷炫動畫。 CSS3 新增了一個很有意思的屬性 -- mix-…

adb錯誤 - INSTALL_FAILED_NO_MATCHING_ABIS

#背景 換組啦&#xff0c;去了UC國際瀏覽器&#xff0c;被擁抱變化了。還在熟悉階段&#xff0c;嘗試了下adb&#xff0c;然后就碰到了這個INSTALL_FAILED_NO_MATCHING_ABIS的坑。。。 #解決方法 INSTALL_FAILED_NO_MATCHING_ABIS is when you are trying to install an app th…

如何更改從Outlook發送的電子郵件中的“答復”地址

If you’re sending an email on behalf of someone else, you might want people to reply to that person instead of you. Microsoft Outlook gives you the option to choose a different default Reply address to cover this situation. 如果您要代表其他人發送電子郵件&…

visio自定義圖形填充

選中圖形&#xff0c;最上面一欄&#xff1a;開發工具-操作&#xff08;-組合-連接&#xff09;-拆分

Ansible 詳解2-Playbook使用

aaa轉載于:https://www.cnblogs.com/Presley-lpc/p/10107491.html

Angular2官網項目 (4)--路由

行動計劃 把AppComponent變成應用程序的“殼”&#xff0c;它只處理導航 把現在由AppComponent關注的英雄們移到一個獨立的GeneralComponent中 添加路由 創建一個新的DashboardComponent組件 把儀表盤加入導航結構中 路由是導航的另一個名字。路由器就是從一個視圖導航到另…

在Windows 7或Vista資源管理器中禁用縮略圖預覽

If you want to speed up browsing around in explorer, you might think about disabling thumbnail previews in folders. 如果要加快在資源管理器中的瀏覽速度&#xff0c;可以考慮禁用文件夾中的縮略圖預覽。 Note that this works in Windows 7 or Vista 請注意&#xf…

rimraf 秒刪?node_modules

//第一次需要安裝刪除指令 npm install rimraf -g //進入對應目錄后卸載node依賴庫在這里插入代碼片 rimraf node_modules

[Halcon] 算子學習_Calibration_Calibration Object

find_caltab find_marks_and_pose   輸出參數StartPose是標定板的位姿  通過pose_to_hom_mat3d轉化為Hom矩陣可得到下面的關系 3D_Point_Coord_in_Cam Hom_Mat(StartPose) * 3D_Point_Coord_in_Cam ; 轉載于:https://www.cnblogs.com/LoveBuzz/p/10109202.html

mysql 表數據轉儲_在MySQL中僅將表結構轉儲到文件中

mysql 表數據轉儲For this exercise, we will use the mysqldump utility the same as if we were backing up the entire database. 在本練習中&#xff0c;我們將像備份整個數據庫一樣使用mysqldump實用程序。 Syntax: 句法&#xff1a; mysqldump -d -h localhost -u root -…

lenos快速開發腳手架

2019獨角獸企業重金招聘Python工程師標準>>> lenos一款快速開發模塊化腳手架&#xff0c; lenos(p為spring boot版本擴展名)一款快速開發模塊化腳手架&#xff0c;采用spring bootspringSpringMvcmybatisshiroswaggerehcachequartzfreemarkerlayui技術開發&#xff…

把angular(vue等)項目部署在局域網上

在cmd中輸入 ipconfig &#xff0c; 復制自己電腦的ipv4地址在啟動項目的時候加上 --host 192.167.8.100 (本機地址)在同一局域網下&#xff08;wifi&#xff09;其他設備訪問此地址端口號即可訪問此項目

luogu P2257 YY的GCD

嘟嘟嘟 感覺這幾道數論題都差不多&#xff0c;但這到明顯是前幾道的升級版。 推了一大頓只能得60分&#xff0c;不得不看題解。 各位看這老哥的題解吧 我就是推到他用\(T\)換掉\(kd\)之前&#xff0c;然后枚舉\(T\)的。這個轉換確實想不出來啊。 還有最后一句&#xff0c;最終的…

20.4. myisamchk — MyISAM Table-Maintenance Utility

先停止mysqld&#xff0c;在--datadir目錄運行 myisamchk */*.MYI >/dev/null &#xff03;檢查哪些表需要修復修復用以下命令一個個修復&#xff1a; myisamchk -r table.MYI更省事的做法&#xff1a; myisamchk -r /var/lib/mysql/*.MYImyisamchk可用crontab定時最佳化tab…

火狐ok谷歌適配_“ OK Google”在鎖定手機上的安全性越來越高

火狐ok谷歌適配If you use “OK Google” to invoke the Assistant on your phone, things are about to change. Google is removing the “Unlock with Voice Match” feature, so the Assistant is going to get a lot more secure. 如果您使用“確定Google”在手機上調用助…

angular ng-zorro 用組件自身方的法來重置表單校驗

官網文檔的API并沒有提供對應的重置表單校驗函數の說明&#xff0c;在控制臺打印this.validateForm&#xff08;校驗表單對象&#xff09; 往往我們只關注亮色函數、屬性&#xff0c;而這次重置函數藏在__prop__中&#xff01; 激動萬分的使用 this.validateForm.reset()&…

Django用戶注冊、登錄、注銷(一)

使用Django自帶的用戶認證系統編寫認證、登錄、注銷基本功能 功能&#xff1a; 使用Django默認的User表 1&#xff09;注冊 判斷是否已存在此用戶&#xff0c;存在的話提示報錯“用戶已存在”&#xff1b; 判斷兩次輸入的密碼是否一致&#xff0c;不一致的話提示報錯“密碼不一…

1月3日學習內容整理:modelform

1、modelform本質上還是form組件 2、引入 from django.forms import ModelForm 3、創建 class Form(ModelForm): class Meta: modelBook Book就是models.py中定義的類&#xff0c;也就是表 firelds"_ _all_ _" 代表繼承Book表中的所有字…

如何在PowerPoint中自動調整圖片大小

PowerPoint can automatically resize an image to fit a shape. You can also resize multiple images already in your presentation to all be the same size. Here’s how it works. PowerPoint可以自動調整圖像大小以適合形狀。 您還可以將演示文稿中已有的多個圖像調整為…

vue目錄結構

vue目錄結構參考一參考二參考三參考一 目錄一級二級bulid項目構建的一些 js 文件config配置文件項&#xff0c;index.js 比較重要&#xff0c;打包上線需要修改配置dist項目打包后的文件node_modulesnpm安裝包位置src項目的開發目錄-assets圖片、字體等資源-components公共組件…