0

I have taken the following code from a tutorial and I want to modify it so as to compile in Webpack.. that is in form template script and css.

<html>
       <head>
          <title>VueJs Instance</title>
          <script type = "text/javascript" src = "js/vue.js"></script>
       </head>
       <body>
          <div id = "databinding">
             <div id = "counter-event-example">
                <p style = "font-size:25px;">Language displayed : <b>{{ languageclicked }}</b></p>
                <button-counter
                v-for = "(item, index) in languages"
                v-bind:item = "item"
                v-bind:index = "index"
                v-on:showlanguage = "languagedisp"></button-counter>
             </div>
          </div>
          <script type = "text/javascript">
             Vue.component('button-counter', {
                template: '<button v-on:click = "displayLanguage(item)"><span style = "font-size:25px;">{{ item }}</span></button>',
                data: function () {
                   return {
                      counter: 0
                   }
                },
                props:['item'],
                methods: {
                   displayLanguage: function (lng) {
                      console.log(lng);
                      this.$emit('showlanguage', lng);
                   }
                },
             });
             var vm = new Vue({
                el: '#databinding',
                data: {
                   languageclicked: "",
                   languages : ["Java", "PHP", "C++", "C", "Javascript", "C#", "Python", "HTML"]
                },
                methods: {
                   languagedisp: function (a) {
                      this.languageclicked = a;
                   }
                }
             })
          </script>
       </body>
    </html>

My problem is that I have a "sub-component" named 'button-counter'..

0

1 Answer 1

1

Use Single File Components and define your button-counter and other components there.

In general, if you are already using Webpack, life will be easier if you use SFC for everything.

https://v2.vuejs.org/v2/guide/single-file-components.html

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.