Can I setup <router-view> in Tab component for Essential JS 2 packages

Hi Team,

I try the example:

    <ejs-tab id='element'>
        <e-tabitems>
                    <e-tabitem :header='headerText0' :content="content0"></e-tabitem>
                    <e-tabitem :header='headerText1' :content="content1"></e-tabitem>
                    <e-tabitem :header='headerText2' :content="content2"></e-tabitem>
      </e-tabitems>
    </ejs-tab>

Can I setup the <router-view></router-view> in "content0" to show the choosen vue in Tab?
Just like <iframe src="xxx.html"></iframe> in "content0".
 
Thanks,




11 Replies 1 reply marked as answer

VD Vinitha Devi Murugan Syncfusion Team August 4, 2020 10:33 AM UTC

Hi Franky,

Syncfusion Greetings.

Yes, you can set up the <router-view></router-view> in "content0" to show the chosen vue in tab. We have prepared a sample below for your reference.


Kindly try the above sample and get back to us if you need any further assistance.

Regards,
M.Vinitha devi


Marked as answer

IL Ivan Loyola June 15, 2023 01:32 PM UTC

Hi M.Vinitha devi

Thank you for your sample, it's exactly what I'm looking for. The only thing I'm flagging is when I try to reach the route through the url, the correct tab isn't selected.


Ivan



SK Satheesh Kumar Balasubramanian Syncfusion Team June 16, 2023 02:27 PM UTC

Hi Ivan,


We have checked the reported issue in previously shared sample. But, reported tab selected issue not occurs from our end. Could you please share the below details to reproduce the issue? This will help to validate the issue and provide prompt solution at earliest.

  • Replicate the issue in previously shared sample (or) share simple issue replicating sample if possible
  • Share all the tab related code snippets
  • Issue reproducing video demo

Regards,
Satheesh Kumar B


IL Ivan Loyola June 16, 2023 07:28 PM UTC

Hi Satheesh :)

Thank you for the reply. To replicate the issue in the above sample. Add a router path to the url in the browser window. tabs.jpg



SK Satheesh Kumar Balasubramanian Syncfusion Team June 19, 2023 02:31 PM UTC

Hi Ivan,

We have used the browser watch option to select the corresponding tab item.


DefaultMenu.vue:

export default Vue.extend({
  name: "DefaultMenu",
  data() {
    return {
      index: 1,
      isLoadRoutingContentWatch: false,
      isLoadRoutingContentEvent: false,
      headerText0: { text: "Angular" },
      headerText1: { text: "Javascript" },
      headerText2: { text: "Service" },
    };
  },
  watch: {
    $route(to, from) {
      if (to.path === "/angular") {
        this.$refs.tabInstance.select(0);
      } else if (to.path === "/javascript") {
        this.$refs.tabInstance.select(1);
      } else if (to.path === "/services") {
        this.$refs.tabInstance.select(2);
      }
      this.StartRouting(to.path);
    },
  },
  methods: {
    loadRoutingContent(args) {
      var urlData;
      if (args.selectedIndex === 0) {
        urlData = "/angular";
      } else if (args.selectedIndex === 1) {
        urlData = "/javascript";
      } else if (args.selectedIndex === 2) {
        urlData = "/services";
      }
      this.StartRouting(urlData);
    },
    StartRouting: function (path) {
      if (path && this.$route.path !== path) {
        //Performs routing...
        this.$router.push(path);
      }
    },
  },
});
</script>

Regards,
Satheesh Kumar B


IL Ivan Loyola June 19, 2023 06:22 PM UTC

Hi Satheesh,


https://www.syncfusion.com/downloads/support/common/4794/ze/syncfusion_tabs_movie.mp4_40bf57fb.zip I have shared a screen recording of the sample with the watch option. I had to zip in since your file upload doesn't support mp4. Looks like its tab selected for a sec before in reverts back.



VR Vijay Ravi Syncfusion Team June 20, 2023 03:20 PM UTC

Hi Ivan,


Your reported issue only occurs in code sandbox sample preview and the same works fine if we open the same output in the individual browser tab. So, we prepare a local sample with same codes, and it works as expected. Try the shared sample and let us know if you need any further assistance.


Regards,

Vijay Ravi


Attachment: TabComponent_505fbc81.zip


IL Ivan Loyola June 23, 2023 07:16 PM UTC

And how would this be accomplished in Vue 3 composition api where the ref is on the component? I tried converting your example but the tabinstance isn't available on the ref $el. Thank you.



SK Satheesh Kumar Balasubramanian Syncfusion Team June 26, 2023 01:33 PM UTC

Hi Ivan,

You can access the tab instance in Vue 3 composition api as shown in the below code snippets.

DefaultMenu.vue:

<template>
  <div>
    <div class="control_wrapper">
      <ejs-tab id="tab_default" ref="Tab_instance" heightAdjustMode="Auto" :selected="loadRoutingContent" ref="tabInstance">
        <e-tabitems>
          <e-tabitem :header="headerText0" :content="idv1"></e-tabitem>
          <e-tabitem :header="headerText1" :content="idv1"></e-tabitem>
          <e-tabitem :header="headerText2" :content="idv1"></e-tabitem>
        </e-tabitems>
      </ejs-tab>
      <div id="idv1">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";

import Vuex from "vuex";
import { TabPlugin } from "@syncfusion/ej2-vue-navigations";
import { ref } from "vue";

Vue.use(TabPlugin);

Vue.use(Vuex);
const Tab_instance = ref(null);

export default Vue.extend({
  name: "DefaultMenu",
  data() {
    return {
      index: 1,
      isLoadRoutingContentWatch: false,
      isLoadRoutingContentEvent: false,
      headerText0: { text: "Angular" },
      headerText1: { text: "Javascript" },
      headerText2: { text: "Service" },
    };
  },
  watch: {
    $route(to) {
      var tabObj = Tab_instance.value.$el.ej2_instances[0];
      if (to.path === "/angular") {
        tabObj.select(0);
      } else if (to.path === "/javascript") {
        tabObj.select(1);
      } else if (to.path === "/services") {
        tabObj.select(2);
      } else {
        tabObj.select(0);
      }
      this.StartRouting(to.path);
    },
  },
  methods: {
    loadRoutingContent(args) {
      var urlData;
      if (args.selectedIndex === 0) {
        urlData = "/angular";
      } else if (args.selectedIndex === 1) {
        urlData = "/javascript";
      } else if (args.selectedIndex === 2) {
        urlData = "/services";
      }
      this.StartRouting(urlData);
    },
    StartRouting: function (path) {
      if (path && this.$route.path !== path) {
        //Performs routing...
        this.$router.push(path);
      }
    },
  },
});
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style></style>


Regards,
Satheesh Kumar B


IL Ivan Loyola June 26, 2023 07:29 PM UTC

$el.ej2_instances[0] Is returning Undefined

I have created a ticket, please and thank you.

https://support.syncfusion.com/support/tickets/476971



SK Satheesh Kumar Balasubramanian Syncfusion Team June 27, 2023 10:02 AM UTC

Hi Ivan,


Thanks for your update.


We will check and update the details in the ticket.

 

Regards,

Satheesh Kumar B 


Loader.
Up arrow icon