本文主要是介绍vue + elementui 项目中使用clipboard2 复制标题时提示this.$messsage is not a function,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
vue + elementui 项目中使用clipboard2
1.安装依赖包
npm install vue-clipboard2 --save
2.在项目main.js 文件中引入
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
3.具体页面中使用
// 复制标题到剪贴板titleCopy(row) {const _this = thisthis.$copyText(`${row.code} ${row.name}`).then(function(e) {_this.$message.success(' 已复制到剪贴板!')console.log(e, '-----------')}, function(e) {_this.$message.warning(' 该浏览器不支持自动复制')})},
其中的关键是
const _this = this
错误示范
第一次使用时,按照官方文档只写了此代码
// 复制标题到剪贴板titleCopy(row) {this.$copyText(`${row.code} ${row.name}`).then(function(e) {this.$message.success(' 已复制到剪贴板!')console.log(e, '-----------')}, function(e) {this.$message.warning(' 该浏览器不支持自动复制')})},
此时报错
这篇关于vue + elementui 项目中使用clipboard2 复制标题时提示this.$messsage is not a function的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!