Search code examples
c#asp.net-mvcvue.jsmodel-view-controllerbootstrap-vue

How to I call 2 variables in Vuejs?


I am using Vuejs.

And I want to call 2 variables.

How should I do?

These are my real codes.

(I want to add a codes that will hide the (x) button in a modal with a class [.close])

I edited my previous post. Sorry 'bout that.

    window.app = new Vue({
    el: '#vuelayoutdiv',
    data: {
        text: null
    },
    methods: {
        submitToSignIn: function () {
            window.location.href = "/{Contoller}/{Index}"
        },
        checkEmail: function (e) {
            if (this.text) {
                return true;
            };
            if (!this.text) {
                this.$bvModal.show('emailmodal');
            }
        }

    }

});

   <b-modal id="emailmodal" hide-footer>
        @*<template v-slot:modal-title>
            Using
            <code>$bvModal</code> Methods
        </template>*@
        <div class="d-block text-center">
            <h3  style="text-align:left">Email required.</h3>
        </div>
        <b-button class="mt-3" block v-on:click="$bvModal.hide('emailmodal')">Close Me</b-button>
    </b-modal>
<b-nav-item class="navbarsigntext signin" v-on:click="submitToSignIn">SIGN IN</b-nav-item>

Solution

  • It's easy to access other Vue instances variables. Although this isn't really common practice, and I'm not really sure what you are trying to do.

    Here is an example, where there is thre instances in total, where the third, gets the message variable from object one and two.

    var vueObj1 = new Vue({
      data () {
        return {
          message: "vueobj1"
        }
      },
    })
    
    var vueObj2 = new Vue({
      data () {
        return {
          message: "vueobj2"
        }
      },
    })
    
    var vueObj3 = new Vue({
      el: '#app',
      computed: {
        messageFromOtherInstances () {
          return vueObj1.message + ' ' + vueObj2.message
        }
      }
    })
    

    I've a small codepen for you, to play with: https://codepen.io/dasmikko/pen/XWWybdr