NaiveUI安装及使用

本文介绍了如何在Vue项目中安装并全局引入NaiveUI组件库,包括按需引入和处理依赖问题,以及如何集成图标库@vicons/ionicons5,并展示了如何使用message提示功能。
摘要由CSDN通过智能技术生成
1、安装UI组件库 naive-ui

yarn add naive-ui

 

2、全局按需引入

src下新建uitls目录并添加uaiveUI.ts

// src/utils/naiveUI.ts

import {

  create,

  NButton

} from 'naive-ui'

export const naiveUI = create({

  components: [NButton]

})

 

3、在main.ts中导入可全局使用

import { createApp } from 'vue'

import './style.css'

import App from './App.vue'

import router from './router'

import { naiveUI } from './utils/naiveUI'

createApp(App).use(router).use(naiveUI).mount('#app')

 

4、具体页面直接通过标签使用
<template>

  <div id="vditor" style="width: 100%; height: 100%;"/>

  <n-button type="primary" @click="getContent">获取html内容</n-button>

</template>

 

 
5、安装图标库

yarn add @vicons/ionicons5

页面引入使用

import {

  CodeDownload

} from '@vicons/ionicons5'

<n-button type="primary" @click="getContent"><n-icon size="12"><code-download /></n-icon>获取html内容</n-button>

如果报提示:

Cannot find module '@vicons/ionicons5' or its corresponding type declarations.ts(2307)

则在env.d.ts 或 vite-env.d.ts,添加声明即可

declare module '@vicons/ionicons5'

6、使用消息提示message

在全局或需要使用message的地方使用 <n-message-provider>,然后使用 useMessage方法获取对应api,如

// App.vue中用 <n-message-provider> 包裹着,可全局使用

<template>

  <n-message-provider>

<section>……</section>

  </n-message-provider>

</template>

然后在具体子页面使用

import { useMessage } from 'naive-ui'

import { defineComponent } from 'vue'

// content

export default defineComponent({

  setup () {

    const message = useMessage()

    return {

      warning () {

        message.warning('...')

      }

    }

  }

})

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QmagicianRX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值