0

So I have a page with a button. When this button is clicked I would like text to appear, and everytime the button is clicked I would like the text to appear like this:

enter image description here

This is my code:

<v-row>
    <component
    v-for="(component, index) in components"
    :key="index"
    :is="component"/>
</v-row>

<v-row justify="left" class="ml-3">
    <v-btn class="elevation-7 grey darken-1 btn" @click="add">Click me</v-btn>
</v-row>

<script>
import Vue from 'vue'
Vue.component('component', {
        template: '<p>component</p>'
    })

export default {
        data: () => {
            return {
                components: [Comp]
            };
        },

        methods: {
            add: function () {
                this.components.push(Comp)
            }
        }
}
</script>

Yet when I click the button nothing appears? I would really appreciate some help as I do not understand this.

UPDATE

I checked console and I am seeing this:

[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

This error then points to this.components.push(Comp) . In vue.config.js I added runtimeCompiler: true yet this error still persists and the text does not appear.

This is all done on vuejs + electron.

1

1 Answer 1

1

It seems like you are using vue2.

Because the compiler is not included in runtime-only builds, you have to set an alias for vue.

    // if you are using webpack
    build: {
        extend(config, ctx){
            config.resolve.alias['vue'] = 'vue/dist/vue.common';
        }
    },
    
    // if you are using vite
    vite: {
        resolve: {
            alias: {
                'vue': 'vue/dist/vue.common'
            }
        },
    }

for more details, please view the docs: Runtime + Compiler vs. Runtime-only

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.