Vue實(shí)現(xiàn)簡(jiǎn)單彈窗效果
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)簡(jiǎn)單彈窗效果的具體代碼,供大家參考,具體內(nèi)容如下
選中input 彈出選項(xiàng)框
顯示彈窗
首先要在components中新建兩個(gè)組件 要實(shí)現(xiàn)子組件向父組件傳值
selest.vue 里面的內(nèi)容
<template> ? <div> ? ? <h1>選擇管理員</h1> ? ? <div class="sel" @click="show">{{ str }}</div> ? ? <template v-if="bol"> ? ? ? <alt @ok="getData($event)" @cancel="close"></alt> ? ? </template> ? </div> </template> <script> import Alt from "./alt.vue"; export default { ? name: "Select", ? data() { ? ? return { ? ? ? bol: false, ? ? ? str: '', ? ? }; ? }, ? components: { ? ? Alt, ? }, ? methods: { ? ? show() { ? ? ? this.bol = true; ? ? }, ? ? // 獲取數(shù)據(jù)方法 ? ? getData(data) { ? ? ? // 關(guān)閉彈出層 ? ? ? this.bol = false; ? ? ? console.log(data); ? ? ? this.str = data; ? ? }, ? ? // 關(guān)閉彈窗 ? ? close() { ? ? ? // 關(guān)閉彈出層 ? ? ? this.bol = false; ? ? }, ? }, }; </script> <style scoped> .sel { ? width: 200px; ? height: 40px; ? border: 1px solid #ccc; ? line-height: 40px; ? text-align: center; ? cursor: pointer; ? margin: 0 auto; } </style>
alt.vue 里面的內(nèi)容
<template> ? <div class="mark"> ? ? <div class="alert"> ? ? ? <!-- 內(nèi)容 --> ? ? ? <div class="cont"> ? ? ? ? <div> ? ? ? ? ? <!-- 左邊的列表 --> ? ? ? ? ? <dl class="left"> ? ? ? ? ? ? <dt> ? ? ? ? ? ? ? <label><input type="checkbox" v-model="allBol" :checke="allBol" @change="all" />全選</label> ? ? ? ? ? ? </dt> ? ? ? ? ? ? <dd v-for="(item,index) in arrL" :key="index"> ? ? ? ? ? ? ? <label> ? ? ? ? ? ? ? ? <input type="checkbox" :checked="item.bol" v-model="item.bol" @change="only(index)" /> ? ? ? ? ? ? ? ? <img :src="item.headurl" alt=""> ? ? ? ? ? ? ? ? <span>{{item.name}}</span> ? ? ? ? ? ? ? </label> ? ? ? ? ? ? </dd> ? ? ? ? ? </dl> ? ? ? ? </div> ? ? ? ? <div> ? ? ? ? ?<dl class="left"> ? ? ? ? ? ? <dd v-for="(item,index) in arrR" :key="index"> ? ? ? ? ? ? ? <label> ? ? ? ? ? ? ? ? <img :src="item.headurl" alt=""> ? ? ? ? ? ? ? ? <span>{{item.name}}</span> ? ? ? ? ? ? ? </label> ? ? ? ? ? ? ? <em @click="del(item,index)">×</em> ? ? ? ? ? ? </dd> ? ? ? ? ? </dl> ? ? ? ? </div> ? ? ? </div> ? ? ? <!-- 按鈕 --> ? ? ? <div class="btns"> ? ? ? ? <button @click="sure">確定</button> ? ? ? ? <button @click="cancel">取消</button> ? ? ? </div> ? ? </div> ? </div> </template> <script> export default { ? data() { ? ? return { ? ? ? allBol: false, ? ? ? arrL: [ ? ? ? ? { name: '花木蘭', id: 1, headurl: require('../assets/logo.png'), bol: false }, ? ? ? ? { name: '拓跋燾', id: 2, headurl: require('../assets/logo.png'), bol: false }, ? ? ? ? { name: '宇文泰', id: 1, headurl: require('../assets/logo.png'), bol: false }, ? ? ? ? { name: '宇文成都', id: 1, headurl: require('../assets/logo.png'), bol: false }, ? ? ? ? { name: '宇文護(hù)', id: 1, headurl: require('../assets/logo.png'), bol: false }, ? ? ? ? { name: '宇文拓', id: 1, headurl: require('../assets/logo.png'), bol: false } ? ? ? ], ? ? ? arrR: [] ? ? } ? }, ? methods: { ? ? // 點(diǎn)擊全選 ? ? all() { ? ? ? // 清空一個(gè)數(shù)組 ? ? ? this.arrR = []; // 第一種 ? ? ? // this.arrR.length = 0; // 第二種 ? ? ? this.arrL.map(item => { ? ? ? ? item.bol = this.allBol; ? ? ? ? if(this.allBol) { ? ? ? ? ? this.arrR.push(item); ? ? ? ? } ? ? ? }) ? ? }, ? ? // 點(diǎn)擊單選 ? ? only(n) { ? ? ?if (this.arrL[n].bol) { ? ? ? ?this.arrR.push(this.arrL[n]) ? ? ?}else { ? ? ? ?let index = this.arrR.indexOf(this.arrL[n]); ? ? ? ?this.arrR.splice(index,1); ? ? ? ?this.allBol = false ? ? ?} ? ? }, ? ? // 刪除 ? ? del(obj, index) { ? ? ? let n = this.arrL.indexOf(obj); ? ? ? this.arrL[n].bol = false; ? ? ? this.arrR.splice(index, 1) ? ? }, ? ? // 點(diǎn)擊確定 ? ? sure() { ? ? ? let arr = []; ? ? ? this.arrR.map(item => { ? ? ? ? arr.push(item.name) ? ? ? }) ? ? ? this.$emit('ok', arr.join(',')); ? ? }, ? ? // 點(diǎn)擊取消 ? ? cancel() { ? ? ? this.$emit('cancel') ? ? }, ? } }; </script> <style scoped> .mark { ? width: 100%; ? height: 100%; ? background: rgba(0, 0, 0, 0.5); ? position: fixed; ? left: 0; ? top: 0; ? z-index: 1000; ? display: flex; ? align-items: center; ? justify-content: center; } .alert{ ? background: #fff; ? width: 800px; ? height: 600px; } .cont { ? display: flex; ? height: 500px; } .cont>div { ? flex: 1; } .cont>div:nth-child(1) { ? border-right: 1px #ccc solid; } .btns { ? height: 100px; ? text-align: center; } .left dd { ? height: 50px; ? margin-bottom: 10px; ? position: relative; } .left dd label { ? display: flex; ? height: 50px; ? align-items: center; ? cursor: pointer; } .left dd label:hover { ? background: #f0f0f0; } .left dd label img { ? width: 50px; ? height: 50px; ? border-radius: 50%; ? margin: 0 5px; } .left dd em { ? cursor: pointer; ? position: absolute; ? width: 50px; ? height: 50px; ? font-size: 30px; ? text-align: center; ? line-height: 50px; ? right: 0; ? top: 0; ? transition: all 0.8s; } .left dd em:hover{ ? transform: rotate(360deg); } </style>
在App.vue 里面寫
<template> ? <div id="app"> ? ? <div id="nav"> ? ? ? <router-link to="/select">選擇管理員</router-link> ? ? </div> ? ? <router-view/> ? </div> </template>
在router 下面的index.js 里面添加路由
import Vue from 'vue' import VueRouter from 'vue-router' import Home from '../views/Home.vue' Vue.use(VueRouter) const routes = [ ? { ? ? path: '/', ? ? name: 'Home', ? ? component: Home ? }, ? { ? ? path: '/about', ? ? name: 'About', ? ? component: function () { ? ? ? return import('../views/About.vue') ? ? } ? }, ? // 創(chuàng)建的路由 ? { ? ? path: '/select', ? ? name: 'Select', ? ? component: () => import('../components/selest.vue') ? } ] const router = new VueRouter({ ? mode: 'history', ? base: process.env.BASE_URL, ? routes }) export default router
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 使用Vue組件實(shí)現(xiàn)一個(gè)簡(jiǎn)單彈窗效果
- 關(guān)于vue.js彈窗組件的知識(shí)點(diǎn)總結(jié)
- vue實(shí)現(xiàn)點(diǎn)擊按鈕“查看詳情”彈窗展示詳情列表操作
- 很棒的vue彈窗組件
- vue彈窗消息組件的使用方法
- vue中實(shí)現(xiàn)點(diǎn)擊空白區(qū)域關(guān)閉彈窗的兩種方法
- VUE實(shí)現(xiàn)可隨意拖動(dòng)的彈窗組件
- Vue中關(guān)閉彈窗組件時(shí)銷毀并隱藏操作
- vue的toast彈窗組件實(shí)例詳解
- vue 實(shí)現(xiàn)一個(gè)簡(jiǎn)單的全局調(diào)用彈窗案例
相關(guān)文章
el-tree樹(shù)狀控件如何定位到選中的節(jié)點(diǎn)的位置
這篇文章主要介紹了el-tree樹(shù)狀控件如何定位到選中的節(jié)點(diǎn)的位置,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-08-08詳解vue axios用post提交的數(shù)據(jù)格式
這篇文章主要介紹了詳解vue axios用post提交的數(shù)據(jù)格式,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08vue a標(biāo)簽點(diǎn)擊實(shí)現(xiàn)賦值方式
這篇文章主要介紹了vue a標(biāo)簽點(diǎn)擊實(shí)現(xiàn)賦值方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09解決VUE 在IE下出現(xiàn)ReferenceError: Promise未定義的問(wèn)題
這篇文章主要介紹了解決VUE 在IE下出現(xiàn)ReferenceError: Promise未定義的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11基于elementUI實(shí)現(xiàn)圖片預(yù)覽組件的示例代碼
這篇文章主要介紹了基于elementUI實(shí)現(xiàn)圖片預(yù)覽組件的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03