0

As I hope to use selected textarea, I found Javascript, but I don't know how to use it as the vue script

 $(document).ready(function () {$(".editorHTMLDIV").hide();}); 
 function convertToHTML() { 
   $('.editorHTMLDIV').text($('.editorDIV').html());
   $('.editorHTMLDIV').show(); 
   $('.editorDIV').hide();

I want to use this Javascript as Vue script like

<template>
  <div>
  </div>
</template>
<script> 
I wanna know this area
</script>
3
  • Could you provide a piece of your HTML code? Also, when do you want the convertToHTML function to be called? Commented Aug 10, 2020 at 9:38
  • jQuery is a DOM manipulation library, Vue is a template binding framework. They are very different concepts. You have taken the most basic form of a piece of jQuery logic and asked how to translate it to Vue. There is no real direct translation, you just need to learn some Vue. Commented Aug 10, 2020 at 9:49
  • Thx all comments, I just started studying Vue.js I wish I could do like yours :) Commented Aug 11, 2020 at 5:20

1 Answer 1

1

You could do something like this:

<template>
    <div>
    </div>
</template>

<script>
export default {
    name: "name-of-your-component",
    data: function () {
        return { };
    },
    methods: {
        convertToHTML: function () {
            $('.editorHTMLDIV').text($('.editorDIV').html());
            $('.editorHTMLDIV').show(); 
            $('.editorDIV').hide();
        },
    },
    mounted() {
        $(".editorHTMLDIV").hide();
    },
}
</script>

However, the above script is just a sample and it probably will not meet your specification requirements (you have not mentioned any in your question).

Likewise, I would strongly recommend that you study the Vue lifecycle which can be found here and also, the Vue library in general.

Also, the jQuery library and the Vue framework are two completely different aspects. You cannot just translate code from one to another.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.