This article mainly introduces cube-ui, a mobile component library based on Vue.js. Now I share it with you and give it as a reference.
cube-ui is an exquisite mobile component library implemented by Didi's technical team based on Vue.js. It's great. Although there are not many components, it is enough for basic scenarios. Thanks for the open source!
First create a vue project
vue init webpack my-project cd my-project npm install
Install cube-ui
npm install cube-ui -S
The official recommendation is to use the babel-plugin-transform-modules plug-in, which can introduce component modules and corresponding modules more elegantly style.
npm install babel-plugin-transform-modules -D
Then configure this plug-in and modify .babelrc: (Add to plugins)
{ "plugins": [ ["transform-modules", { "cube-ui": { "transform": "cube-ui/lib/${member}", "kebabCase": true, "style": { "ignore": ["create-api", "better-scroll"] } } }] ] }
Introduction method 1: Import all
General In the entry file main.js:
import Vue from 'vue' import Cube from 'cube-ui' // 一般直接放在这个位置 Vue.use(Cube)
After all are introduced, it is equivalent to global registration, and you can use it directly. There is no need to import {…} (local reference) in each .vue file, and components{…} are locally registered.
Introduction method 2: Import on demand
import { /* eslint-disable no-unused-vars */ Style, // 必需 Button } from 'cube-ui'
Note: If imported on demand, the basic style part will not be packaged, so you need to introduce style when using it module.
Registration methodOptional global registration or local registration:
// 全局注册 Vue.use(Button) // 在入口文件中 // 或者局部注册 // 某个组件中 { components: { CubeButton: Button } }
All components that can be introduced on demand:
import { Button, Checkbox, Loading, Tip, Toast, Picker, TimePicker, Dialog, ActionSheet, Scroll, Slide, IndexList } from 'cube-ui'
can also be introduced create-api and better-scroll modules:
import { createAPI, BetterScroll } from 'cube-ui'
Example
<template> <cube-button @click="showDiaog">show dialog<cube-button> </template> <script> export default { methods: { showDialog() { this.$createDialog({ type: 'alert', title: 'Alert', content: 'dialog content' }).show() } } } </script>
Do not use post-compilation
Note: cube-ui with webpack 2 will use post-compile by default, but Post-compilation requires some dependencies and configurations (see the end of this page); if you don’t want to use post-compilation, you can directly modify the webpack configuration:
// webpack.config.js module.exports = { // ... resolve: { // ... alias: { // ... 'cube-ui': 'cube-ui/lib' // ... } // ... } // ... }
Use post-compile
cube-ui combination After webpack 2, post-compilation will be used by default, so the application needs to be compatible with cube-ui's dependencies and configuration.
1. Modify package.json
{ // webpack-post-compile-plugin 依赖 compileDependencies "compileDependencies": ["cube-ui"], "devDependencies": { "babel-plugin-transform-modules": "^0.0.2", // 新增 stylus 相关依赖 (都需要额外安装:npm install … -D) // stylus 类似于 sass,less "stylus": "^0.54.5", "stylus-loader": "^2.1.1", "webpack-post-compile-plugin": "^0.1.2" } }
2. Modify .babelrc and still rely on babel-plugin-transform-modules:
"plugins": [ ["transform-runtime"], ["transform-modules", { "cube-ui": { // 注意: 这里的路径需要修改到 src/modules 下 "transform": "./node_modules/cube-ui/src/modules/${member}", "kebabCase": true } }] ]
3. Modify webpack.base.conf .js
var PostCompilePlugin = require('webpack-post-compile-plugin') module.exports = { // ... plugins: [ // ... new PostCompilePlugin() ] // ... }
4. Modify the exports.cssLoaders function in build/utils.js
exports.cssLoaders = function (options) { // ... const stylusOptions = { 'resolve url': true } // https://vue-loader.vuejs.org/en/configurations/extract-css.html return { css: generateLoaders(), postcss: generateLoaders(), less: generateLoaders('less'), sass: generateLoaders('sass', { indentedSyntax: true }), scss: generateLoaders('sass'), stylus: generateLoaders('stylus', stylusOptions), styl: generateLoaders('stylus', stylusOptions) } }
Run and see the results:
npm run dev
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to implement high-performance loading sequence in javascript
##How to implement global registration in axios
How to implement login verification jump using Vue Flask (detailed tutorial)
About usage of connect decorator in react-redux
The above is the detailed content of How to use mobile component library in Vue.js (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

jQuery is a great JavaScript framework. However, as with any library, sometimes it’s necessary to get under the hood to discover what’s going on. Perhaps it’s because you’re tracing a bug or are just curious about how jQuery achieves a particular UI

This post compiles helpful cheat sheets, reference guides, quick recipes, and code snippets for Android, Blackberry, and iPhone app development. No developer should be without them! Touch Gesture Reference Guide (PDF) A valuable resource for desig


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
