Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@uni/clipboard

raxjs3.6kBSD-3-Clause1.0.9TypeScript support: included

npm

readme

getClipboard

npm

Install

$ npm install @uni/clipboard --save

or

$ npm install @uni/apis --save

Usage

import { getClipboard } from '@uni/clipboard';

getClipboard({
  success (res){
    console.log(res.text);
  }
});

// promise
getClipboard().then(res => {
  console.log(res.text);
});

Methods

getClipboard()

Gets the content on the system clipboard.

Supported

miniApp wechatMiniprogram bytedanceMicroApp baiduSmartProgram kuaiShouMiniProgram

Arguments

Property Type Description required Default
options object | ✔️ -
options.success Function The callback function for a successful API call -
options.fail Function The callback function for a failed API call -
options.complete Function The callback function used when the API call completed (always executed whether the call succeeds or fails) -

Return

Property Type Description
res object
res.text string The clipboard content

setClipboard

Sets the content on the system clipboard.

Supported

browser miniApp wechatMiniprogram bytedanceMicroApp baiduSmartProgram kuaiShouMiniProgram

Usage

import { setClipboard } from '@uni/clipboard';

setClipboard({
  text: 'text',
  success (res){
    console.log(res);
  }
});

// promise
setClipboard({
  text: 'text'
}).then(res => {
  console.log(res);
});

Arguments

Property Type Description required Default
options object | ✔️ -
options.text string The clipboard content ✔️ -
options.success Function The callback function for a successful API call -
options.fail Function The callback function for a failed API call -
options.complete Function The callback function used when the API call completed (always executed whether the call succeeds or fails) -