Giter Site home page Giter Site logo

vxe-table-demo's Introduction

vxe-table 使用示例

安装指南

v1 vue 2.6 依赖: npm install vxe-table@1 xe-utils@2
v2 vue 2.6 依赖: npm install vxe-table@2 xe-utils@3
v3 vue 2.6 依赖: npm install vxe-table@3 xe-utils@3
v4 vue next 依赖: npm install vxe-table@next xe-utils@3

v2 ~ v3 全局导入

src/plugins/vxe-table

import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'

Vue.use(VXETable)

src/main

import Vue from 'vue'
import App from './App.vue'

import './plugins/vxe-table'

new Vue({
  render: h => h(App)
}).$mount('#app')

v2 ~ v3 babel 按需导入

安装 babel 插件,配置插件

npm install babel-plugin-import -D

修改 .babelrc 或 babel.config.js 配置文件

module.exports = {
  plugins: [
    [
      'import',
      {
        'libraryName': 'vxe-table',
        'style': true
      }
    ]
  ]
}

src/plugins/vxe-table

import Vue from 'vue'
import XEUtils from 'xe-utils'
import {
  VXETable,
  Icon,
  Header,
  Column,
  Table
} from 'vxe-table'
import zhCNLocat from 'vxe-table/lib/locale/lang/zh-CN'

// 导入默认的国际化(如果项目中使用多语言,则应该导入到 vue-i18n 中)
VXETable.setup({
  i18n: (key, args) => XEUtils.toFormatString(XEUtils.get(zhCNLocat, key), args)
})

Vue.use(Icon)
Vue.use(Header)
Vue.use(Column)
Vue.use(Table)

src/main

import Vue from 'vue'
import App from './App.vue'

import './plugins/vxe-table'

new Vue({
  render: h => h(App)
}).$mount('#app')

v4 全局导入

src/plugins/vxe-table

import { App } from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'

// 全局默认参数
VXETable.setup({
  version: 0,
  zIndex: 100,
  table: {
    autoResize: true
  }
})

export function useTable (app: App) {
  app.use(VXETable)
}

src/main

import { createApp } from 'vue'
import App from './App.vue'

import { useTable } from './plugins/vxe-table'

createApp(App).use(useTable).mount('#app')

v4 babel 按需导入

安装 babel 插件,配置插件

npm install babel-plugin-import -D

修改 .babelrc 或 babel.config.js 配置文件

module.exports = {
  plugins: [
    [
      'import',
      {
        'libraryName': 'vxe-table',
        'style': true
      }
    ]
  ]
}

src/plugins/vxe-table

import { App } from 'vue'
import XEUtils from 'xe-utils'
import {
  VXETable,
  Header,
  Icon,
  Column,
  Table
} from 'vxe-table'
import zhCNLocat from 'vxe-table/lib/locale/lang/zh-CN'

// 全局默认参数
VXETable.setup({
  version: 0,
  zIndex: 100,
  table: {
    autoResize: true
  }
})

// 导入默认的国际化(如果项目中使用多语言,则应该导入到 vue-i18n 中)
VXETable.setup({
  i18n: (key, args) => XEUtils.toFormatString(XEUtils.get(zhCNLocat, key), args)
})

export function useTable (app: App) {
  app.use(Header)
    .use(Icon)
    .use(Column)
    .use(Table)
}

src/main

import { createApp } from 'vue'
import App from './App.vue'

import { useTable } from './plugins/vxe-table'

createApp(App).use(useTable).mount('#app')

v4 vite 按需导入

安装 vite 插件,配置插件

npm vite-plugin-style-import -D

修改 vite.config.ts 配置文件

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import styleImport from 'vite-plugin-style-import'

export default defineConfig({
  plugins: [
    vue(),
    styleImport({
      libs: [
        {
          libraryName: 'vxe-table',
          esModule: true,
          resolveComponent: (name) => `vxe-table/es/${name}`,
          resolveStyle: (name) => `vxe-table/es/${name}/style.css`
        }
      ]
    })
  ]
})

src/plugins/vxe-table

import { App } from 'vue'
import XEUtils from 'xe-utils'
import {
  VXETable,
  Header,
  Icon,
  Column,
  Table
} from 'vxe-table'
import zhCNLocat from 'vxe-table/es/locale/lang/zh-CN'

// 全局默认参数
VXETable.setup({
  version: 0,
  zIndex: 100,
  table: {
    autoResize: true
  }
})

// 导入默认的国际化(如果项目中使用多语言,则应该导入到 vue-i18n 中)
VXETable.setup({
  i18n: (key, args) => XEUtils.toFormatString(XEUtils.get(zhCNLocat, key), args)
})

export function useTable (app: App) {
  app.use(Header)
    .use(Icon)
    .use(Column)
    .use(Table)
}

src/main

import { createApp } from 'vue'
import App from './App.vue'

import { useTable } from './plugins/vxe-table'

createApp(App).use(useTable).mount('#app')

vxe-table-demo's People

Contributors

xuliangzhan avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.