中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

報(bào)考建設(shè)八大員官方網(wǎng)站seo推廣軟件哪個(gè)好

報(bào)考建設(shè)八大員官方網(wǎng)站,seo推廣軟件哪個(gè)好,詳情頁生成器,網(wǎng)站初期推廣文章目錄前言1.訪問模板引用2.v-for中的模板引用3.組件上的ref前言 如果我們需要直接訪問組件中的底層DOM元素,可使用vue提供特殊的ref屬性來訪問 1.訪問模板引用 在視圖元素中采用ref屬性來設(shè)置需要訪問的DOM元素 a. 該ref屬性可采用字符值的執(zhí)行設(shè)置 b. 該ref屬…

文章目錄

  • 前言
  • 1.訪問模板引用
  • 2.v-for中的模板引用
  • 3.組件上的ref


前言

如果我們需要直接訪問組件中的底層DOM元素,可使用vue提供特殊的ref屬性來訪問


1.訪問模板引用

  1. 在視圖元素中采用ref屬性來設(shè)置需要訪問的DOM元素
    a. 該ref屬性可采用字符值的執(zhí)行設(shè)置
    b. 該ref屬性可采用v-bind:或:ref的形式來綁定函數(shù),其函數(shù)的第一個(gè)參數(shù)則為該元素
  2. 如果元素的ref屬性值采用的是字符串形式
    a. 在選項(xiàng)式 API JS中,可通過this.$refs來訪問模板引用
    b. 在組合式 API JS中,我們需要聲明一個(gè)同名的ref變量,來獲得該模板的引用

訪問模板引用【選項(xiàng)式】

<script>
export default {data: () => ({accountEl: null,passwordEl: null}),methods: {changeAccountInputStyle() {this.accountEl = this.$refs.account // 獲取賬號(hào)輸入框的 DOMconsole.log(this.accountEl)this.accountEl.style = "padding: 15px"this.accountEl.className = "rounded"this.accountEl.focus()},passwordRef(el) { this.passwordEl = el  // el 元素是密碼輸入框},changePasswordInputStyle() {console.log(this.passwordEl) console.log(this.$refs) // 函數(shù)式聲明的 ref,不會(huì)在this.$refs中獲取this.passwordEl.style = "padding: 15px"this.passwordEl.className = "rounded"this.passwordEl.focus()},}
}
</script><template><!-- ref 字符串值形式 -->賬號(hào)輸入框:<input type="text" ref="account"><button @click="changeAccountInputStyle">改變賬號(hào)輸入框的樣式</button><hr><!-- ref 函數(shù)形式:元素渲染后,會(huì)立即執(zhí)行該函數(shù) -->密碼輸入框:<input type="password" :ref="passwordRef"><button @click="changePasswordInputStyle">改變密碼輸入框的樣式</button>
</template><style>
.rounded {border-radius: 15px;
}
</style>

訪問模板引用【組合式】

<script setup>
import { ref } from 'vue';// 賬號(hào)輸入框
let account = ref(null) // ref 變量名和賬號(hào)輸入框中的 ref 屬性值一樣function changeAccountInputStyle() {console.log(account.value)account.value.style = 'padding: 10px'account.value.className = 'rounded'account.value.focus()
}// ------------------------------------------------------------------------// 密碼輸入框元素
let passwordEl = ref(null)function passwordRef(el) {passwordEl.value = el // el 元素是密碼輸入框
}function changePasswordInputStyle() {console.log(passwordEl.value)passwordEl.value.style = 'padding: 10px'passwordEl.value.className = 'rounded'passwordEl.value.focus()
}
</script><template><!-- ref 字符串值形式 -->賬號(hào)輸入框:<input type="text" ref="account"><button @click="changeAccountInputStyle">改變賬號(hào)輸入框的樣式</button><hr><!-- ref 函數(shù)形式:元素渲染后,會(huì)立即執(zhí)行該函數(shù)-->密碼輸入框:<input type="password" :ref="passwordRef"><button @click="changePasswordInputStyle">改變密碼輸入框的樣式</button>
</template><style>
.rounded {border-radius: 15px;
}
</style>

2.v-for中的模板引用

當(dāng)在v-for中使用模板引用時(shí):

  1. 如果ref值是字符串形式,在元素被渲染后包含對(duì)應(yīng)整個(gè)列表的所有元素【數(shù)組】
  2. 如果ref值是函數(shù)形式,則會(huì)每渲染一個(gè)列表元素則會(huì)執(zhí)行對(duì)應(yīng)的函數(shù)【不推薦使用】

注意:需要v3.2.25及以上版本

列表渲染指令中的模板引用【選項(xiàng)式】

<script>
export default {data: () => ({books: [{ id: 1, name: '紅樓夢(mèng)' },{ id: 2, name: '三國演義' },{ id: 3, name: '水滸傳' },{ id: 4, name: '西游記' }],students: [{ id: 1, name: 'Jack' },{ id: 2, name: 'Annie' },{ id: 3, name: 'Tom' }]}),methods: {changeBookListStyle() {console.log(this.$refs.bookList)this.$refs.bookList[2].style = 'color: red'},studentsRef(el) {console.log(el)}}
}
</script><template><ul><!-- 如果 ref 值是字符串形式,在元素被渲染后包含對(duì)應(yīng)整個(gè)列表的所有元素【數(shù)組】 --><li v-for="b in books" :key="b.id" ref="bookList">{{ b.name }}</li></ul><button @click="changeBookListStyle">點(diǎn)我查看 bookList </button><hr><!-- 如果ref值是函數(shù)形式,則會(huì)每渲染一個(gè)列表元素則會(huì)執(zhí)行對(duì)應(yīng)的函數(shù)【不推薦使用】 --><ul><li v-for="s in students" :key="s.id" :ref="studentsRef">{{ s.name }}</li></ul>
</template>

列表渲染指令中的模板引用【組合式】

<script setup>
import { onMounted, ref } from 'vue';// 書本
let books = ref([{ id: 1, name: '海底兩萬里' },{ id: 2, name: '駱駝祥子' },{ id: 3, name: '老人與海' },{ id: 4, name: '安徒生童話' },
])let bookList = ref(null)onMounted(() => {console.log(bookList.value); // 獲取引用的 DOM 對(duì)象,并打印,發(fā)現(xiàn)那么是數(shù)組,bookList.value[2].className = 'error'
})
</script><template><ul><li v-for="b in books" :key="b.id" ref="bookList">{{ b.name }}</li></ul>
</template><style>
.error {border: 1px solid red;
}
</style>

3.組件上的ref

模板引用也可以被用在一個(gè)子組件上;這種情況下引用中獲得的值是組件實(shí)例

  1. 如果子組件使用的是選項(xiàng)式 API ,默認(rèn)情況下父組件可以隨意訪問該子組件的數(shù)據(jù)和函數(shù),除非在子組件使用expose選項(xiàng)來暴露特定的數(shù)據(jù)或函數(shù),expose值為字符串?dāng)?shù)組
  2. 如果子組件使用的是組合式 API

App.vue【選項(xiàng)式】

<script>
import LoginVue from './components/Login.vue';
export default {components: { LoginVue },data: ()=> ({login_vue: null}),methods: {showSonData() {console.log(this.login_vue.account) // 訪問子組件中的賬號(hào)數(shù)據(jù)console.log(this.login_vue.password) // 訪問子組件中的密碼數(shù)據(jù)this.login_vue.toLogin() // 訪問子組件中的去登陸函數(shù)}},mounted(){this.login_vue = this.$refs.loginView}
}
</script><template><h3>登陸界面</h3><hr><!-- 組件上的 ref 的值為該組件的實(shí)例 --><LoginVue ref="loginView" /><hr><button @click="showSonData">查看子組件中的信息</button>
</template>

Login.vue【選項(xiàng)式】

<script>
// 選項(xiàng)式 API ,默認(rèn)情況下父組件可以隨意訪問該子組件的數(shù)據(jù)和函數(shù)等
export default {data: ()=> ({account: 'Abc31510',password: '123321'}),methods: {toLogin() {console.log('登錄中……');}},// 只暴露指定數(shù)據(jù)、函數(shù)等expose: ['account', 'toLogin']
}
</script><template>賬號(hào):<input type="text" v-model="account"><br>密碼:<input type="text" v-model="password">
</template>
http://www.risenshineclean.com/news/29159.html

相關(guān)文章:

  • wordpress 文章列表只顯示標(biāo)題外貿(mào)seo
  • 哪個(gè)網(wǎng)站做任務(wù)能賺錢我要看今日頭條
  • 廈門廣告公司有哪些aso優(yōu)化的主要內(nèi)容為
  • wordpress修改谷歌外貿(mào)seo公司
  • 做美團(tuán)網(wǎng)這種網(wǎng)站賺錢嗎亞馬遜關(guān)鍵詞搜索器
  • 英語網(wǎng)站建設(shè)如何制作一個(gè)公司網(wǎng)站
  • 上海網(wǎng)站建設(shè)平臺(tái)站霸網(wǎng)絡(luò)seo學(xué)習(xí)網(wǎng)站
  • 做網(wǎng)站有一個(gè)火箭回頂部網(wǎng)站優(yōu)化關(guān)鍵詞公司
  • 做cpa的博客網(wǎng)站類型博客網(wǎng)
  • 優(yōu)惠券推廣網(wǎng)站怎么做seo怎么搞
  • nas網(wǎng)站怎么做網(wǎng)站時(shí)事新聞最新2022
  • 順德樂從有做阿里巴巴的網(wǎng)站嗎sem競(jìng)價(jià)專員是干什么的
  • 做網(wǎng)站視頻圖片加載不出來企業(yè)網(wǎng)站模板下載
  • 情感視頻素材網(wǎng)站劉連康seo培訓(xùn)哪家強(qiáng)
  • 網(wǎng)站建設(shè)和網(wǎng)站推廣可以同一家做嗎網(wǎng)站優(yōu)化排名金蘋果系統(tǒng)
  • 企業(yè)網(wǎng)站建設(shè)英文超級(jí)外鏈
  • 手機(jī)網(wǎng)站哪家好西安百度推廣優(yōu)化
  • 網(wǎng)站開發(fā) 英文文章百度收錄快的發(fā)帖平臺(tái)
  • 福州網(wǎng)頁鄭州seo排名優(yōu)化公司
  • 汕頭網(wǎng)站建設(shè)制作公司衡陽seo快速排名
  • 分類信息網(wǎng)站成都搭建如何搭建一個(gè)網(wǎng)站平臺(tái)
  • 做網(wǎng)站的點(diǎn)子站長(zhǎng)之家ppt素材
  • 同程網(wǎng)站建設(shè)分析朝陽網(wǎng)站建設(shè)公司
  • 深圳住建委網(wǎng)站智謀網(wǎng)站優(yōu)化公司
  • html5門戶網(wǎng)站模板百度人工客服電話多少
  • 鄭州做網(wǎng)站九零后排名點(diǎn)擊工具
  • 網(wǎng)站開發(fā)程序員 工資百度云怎么找資源
  • 貴陽網(wǎng)站建設(shè)多少錢?影視后期培訓(xùn)機(jī)構(gòu)全國排名
  • 如何搭建公司網(wǎng)站上海公關(guān)公司
  • 做美圖 網(wǎng)站有哪些付費(fèi)惡意點(diǎn)擊軟件