获取系统剪切板内容

128 阅读1分钟
function getClipboardData() {
	return new Promise((success, fail) => {
		// #ifndef H5
		uni.getClipboardData({
			success: ({
				data
			}) => success(data),
			fail
		})
		// #endif

		// #ifdef H5
		try {
			navigator.clipboard.readText().then(success).catch(fail)
		} catch (error) {
			fail(error)
		}
		// #endif
	})
}