国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue3 ,naive-ui,嵌套modal踩坑

這篇具有很好參考價值的文章主要介紹了vue3 ,naive-ui,嵌套modal踩坑。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

今天寫代碼,組合使用了,n-modal,n-datatable和n-select,在n-select組件出問題,無法展開,并且報錯

Failed to execute 'insertBefore' on 'Node': This node type does not support this method.
Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at
Cannot read properties of null (reading 'emitsOptions')

先展示錯誤的demo代碼

<script setup lang="ts">
import {  ref } from 'vue'
import {  NButton, NModal } from 'naive-ui'
import ModuleView from './ModuleView.vue';
const showModal_1 = ref(false)

</script>
<template>
  <div>
    <n-button type="info" @click="showModal_1 = true">點擊展開modal</n-button>
    <n-modal v-model:show="showModal_1">
      <ModuleView/>
    </n-modal>
  </div>
</template>

ModuleView是抽象出來的組件,問題就出在這個抽象里面,下面是子組件代碼;

<script setup lang="ts">
import { h, reactive, ref } from 'vue'
import { NSelect, NDataTable, NButton, NModal, NCard } from 'naive-ui'
const optionsRef = ref([
  {
    label: '1',
    value: 1
  },
  {
    label: '2',
    value: 2
  }
])

const columns = reactive([
  {
    title: '序號',
    key: 'index'
  },
  {
    title: '組件A',
    key: 'comp_a',
    render: () =>
      h(
        NSelect,
        {
          options: optionsRef.value,
          style: { width: '200px' }
        },
        {}
      )
  },
  {
    title: '組件B',
    key: 'comp_b',
    render: () =>
      h(NSelect, {
        options: optionsRef.value,
        style: { width: '200px' }
      })
  }
])
const data = ref<any>([])
const handelAdd = () => {
  const item: any = {
    index: data.value.length + 1,
    comp_a: 1,
    comp_b: 2
  }
  data.value.push(item)
}
const showModal_2 = ref(false)
</script>

<template>
  <div>
    <n-card>
      <n-button @click="handelAdd">+</n-button>
      <n-data-table :columns="columns" :data="data"> </n-data-table>
    </n-card>
  </div>

  <n-modal v-model:show="showModal_2"> </n-modal>
</template>

<style scoped></style>

很明顯這是一個嵌套modal的代碼。
效果圖:
slot[default] should have exactly one child.,ui,vue.js,javascript

大伙都知道,vue2的時候template里面第一層只能寫一個組件:

<template>
	<div>
		<div>你好</div>
		<a>hello world<a/>
	</div>
</template>

但是到了vue3就支持多組件了,比如:

<template>
	<div>你好</div>
	<a>hello world<a/>
</template>

我寫vue3保留了vue2的習(xí)慣,只寫一個組件,唯獨用modal的時候習(xí)慣寫到主組件外面,因為這個組件是遮罩的,會覆蓋全頁面。
但是問題也出在這,如果直接在modal里面寫兩個組件,naive會直接報錯。

  <div>
    <n-button type="info" @click="showModal_1 = true">點擊展開modal</n-button>
    <n-modal v-model:show="showModal_1">
      <n-button @click="">+</n-button>
      <n-data-table> </n-data-table>
      <n-modal> </n-modal>
    </n-modal>
  </div>
App.vue:11 [naive/getFirstSlotVNode]: slot[default] should have exactly one child
App.vue:11 [naive/modal]: default slot is empty 這個是錯誤報錯

意思是說,modal里面只能有一個子組件。

    <n-modal v-model:show="showModal_1">
      <ModuleView/>
    </n-modal>

但是如果像我這樣,抽象出來,就不會報錯,會影響子組件內(nèi)部的調(diào)用,導(dǎo)致我一直以為是Select或者DataTable寫錯了。
解決辦法也很簡單,直接把子組件寫成一整個div就好。文章來源地址http://www.zghlxwxcb.cn/news/detail-846104.html

到了這里,關(guān)于vue3 ,naive-ui,嵌套modal踩坑的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • naive-ui在setup引用message的方法

    naive-ui在setup引用message的方法

    序: ? ? ? ? 先說好,能用,而且不用新建啥目錄,但是官方不推薦?。。?!,但是快!??!? ? ? 上圖的的api文檔地址點右邊===》Naive UI 原文是=》如果你想在? setup ?外使用 ? useDialog 、 useMessage 、 useNotification 、 useLoadingBar ,可以通過? createDiscreteApi ?來構(gòu)建對應(yīng)的 API。

    2024年02月03日
    瀏覽(22)
  • 使用@zip.js/zip.js與naive-ui的Tree組件實現(xiàn)在線文件解壓預(yù)覽

    使用@zip.js/zip.js與naive-ui的Tree組件實現(xiàn)在線文件解壓預(yù)覽

    用于壓縮和解壓縮文件的 JavaScript 庫 支持Zip64 格式 支持WinZIP AES和 PKWare ZipCrypto 加密 支持同時讀取和寫入一個或多個 zip 文件 集成工作池管理器 無第三方依賴 該庫依賴于Promise、TypedArray、?Streams?API 以及以下可選的 API: Web Workers Compression Streams Web Crypto 該庫與最新版本的

    2024年02月19日
    瀏覽(23)
  • Vue3 UI組件庫對比,Naive UI、Element Plus、 Ant Design Vue

    Element Plus Naive ui Ant Design Vue 簡介 element-ui Vue3版本,國內(nèi)使用廣泛 Vue作者推薦的Vue3ui 組件庫 阿里Ant Design設(shè)計規(guī)范的Vue實現(xiàn)版 地址 https://github.com/element-plus/element-plus https://github.com/tusen-ai/naive-ui https://github.com/vueComponent/ant-design-vue 社區(qū)活躍度 高 中 高 ui庫組件主要實現(xiàn)方式

    2024年01月25日
    瀏覽(33)
  • Vue3+Vite+Pinia+Naive后臺管理系統(tǒng)搭建之四:Naive UI 組件庫的安裝和使用

    Vue3+Vite+Pinia+Naive后臺管理系統(tǒng)搭建之四:Naive UI 組件庫的安裝和使用

    前言 如果對 vue3 的語法不熟悉的,可以移步?Vue3.0 基礎(chǔ)入門Vue3.0 基礎(chǔ)入門快速入門。 UI 組件請參考官網(wǎng):Naive Ui 官網(wǎng) 為什么選擇 naive ui 不繼續(xù)用 element ui,因為尤大大推薦,可以嘗試下,而且 naive ui 更貼近 vue3 的語法,當(dāng)然易上手還是element ui 好一點。 github 開源庫:Vue

    2024年02月07日
    瀏覽(128)
  • Vue3的幾款UI組件庫:Naive UI、Element Plus、 Ant Design Vue、Arco Design

    vue3系列的三款ui框架簡要對比: 框架 Element Plus Naive ui Ant Design Vue Arco Design 簡介 element-ui Vue3版本,國內(nèi)使用廣泛 Vue作者推薦的Vue3ui 組件庫 Ant Design 的 Vue 實現(xiàn),組件的風(fēng)格與 Ant Design 保持同步 ArcoDesign 主要服務(wù)于字節(jié)跳動旗下中后臺產(chǎn)品的體驗設(shè)計和技術(shù)實現(xiàn) 社區(qū)活躍度

    2024年02月03日
    瀏覽(33)
  • vue3 + typescript + vite + naive ui + tailwindcss + jsx 仿蘋果桌面系統(tǒng)

    vue3 + typescript + vite + naive ui + tailwindcss + jsx 仿蘋果桌面系統(tǒng)

    基于 vue3.x + typescript + vite + naive ui + tailwindcss + jsx + vue-router + pinia,項目使用 tsx 作為模版輸出,全程沒有使用vue提供的SFC, 仿macos桌面前端項目,開源免費模版,希望減少工作量和學(xué)習(xí)新技術(shù),希望能夠幫助大家; 本人主要是后端的開發(fā),對于前端我也是剛?cè)腴T的小白,有很

    2024年02月07日
    瀏覽(22)
  • Naive UI+Vue3來實現(xiàn)點擊按鈕一鍵切換明暗主題的功能

    Naive UI+Vue3來實現(xiàn)點擊按鈕一鍵切換明暗主題的功能

    記錄一下如何使用Naive UI+Vue3代碼來實現(xiàn)一鍵切換明暗主題的功能。 效果如下: 終端下輸入: 起好項目的名稱,然后一路回車即可。 至此Vue3的項目已經(jīng)搭建完畢,打開http://127.0.0.1:5173/就可以看到項目的默認(rèn)首頁了。 安裝Naive UI依賴庫 然后我們根據(jù)官方出的配置對項目進(jìn)行

    2024年02月12日
    瀏覽(75)
  • vue3+Naive UI+fastapi 前后端分離 Pagination 數(shù)據(jù)分頁實戰(zhàn)演練

    vue3+Naive UI+fastapi 前后端分離 Pagination 數(shù)據(jù)分頁實戰(zhàn)演練

    記錄一次vue3+Naive UI+fastapi 前后端分離 Pagination 數(shù)據(jù)分頁實戰(zhàn)演練的過程。 Naive UI 是一個 Vue3 的組件庫。 FastAPI 是一個用于構(gòu)建 API 的現(xiàn)代、快速(高性能)的 web 框架,使用 Python 3.6+ 并基于標(biāo)準(zhǔn)的 Python 類型提示。 fastapi-backend 后端目錄 vue-frontend 前端目錄 這里我只貼一些關(guān)

    2024年02月06日
    瀏覽(45)
  • Vue3 - 解決使用 Tailwindcss 后導(dǎo)致 UI 組件庫樣式受影響,引入后發(fā)現(xiàn)項目組件庫的組件樣式不對了(Element/Ant Design Vue/Naive UI/TDesign)

    網(wǎng)上的教程都無法解決,但本文可以幫助您快速解決該問題。 當(dāng)項目引入 Tailwind css 后,使用 UI 組件庫的某些組件時,發(fā)現(xiàn)有些樣式丟失及顯示錯位、背景色丟失等問題, 頻發(fā)于【按鈕組件】背景色丟失 | 【message消息提示組件】樣式位置變形等,嚴(yán)重的整個組件庫樣式都亂

    2024年02月07日
    瀏覽(29)
  • vue naive ui 按鈕綁定按鍵

    vue naive ui 按鈕綁定按鍵

    知識點: 按鍵綁定Button 全局掛載使得message,notification, dialog, loadingBar 等NaiveUI 生效 UMD方式使用vue 與 naive ui 將vue默認(rèn)的 分隔符大括號 替換 為 [[ ]] https://juejin.cn/post/7188032240775856185 https://www.naiveui.com/zh-CN/os-theme/components/discrete

    2024年02月10日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包