9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vue.jsでクリップボードにコピー

Last updated at Posted at 2020-11-19

やりたいこと

値をmethodに渡してそれをクリップボードにコピーしたい

template部分

<v-icon @click="copyToClipboard(text)">mdi-content-copy</v-icon>

script部分

methods: {
    copyToClipboard(text) {
        navigator.clipboard.writeText(text)
        .then(() => {
            console.log("copied!")
        })
        .catch(e => {
            console.error(e)
        })
    }
}

その他の方法

以下の記事の様に要素を指定してその内容をコピーすることもできる様です
https://qiita.com/ikemura23/items/eec0eed63fc119606451

9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?