M
M
Maxim2020-09-08 09:58:50
Vue.js
Maxim, 2020-09-08 09:58:50

How to copy text from div on button click?

There is a dx-treelist in which there is a div from which you need to copy the text on the click of a button, tell me how to do this? Tried with execCommand("copy"), didn't work

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2020-09-08
@iamd503

https://clipboardjs.com/

A
Alexander, 2020-09-08
@alexmixaylov

you need to hang the handler on the div and make the handler in the methods
<div v-on:click="handler">какой-то текст</div>

handler(e) {
const text = e.target.innerText
// сюда попадет ваш текст
}

B
Benchstyle, 2020-09-08
@Benchstyle

For example, pass text through data or props.

<div v-on:click="handler">{{someText}}</div>

  data(){
    return {
      someText: 'Какой-то текст...'
    }
  },
  methods: {
    handler() {
      return this.someText;
    }
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question