question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic content in Vue components

See original GitHub issue

Bug Report

In the documentation it says that one can embed Vue instances. I tried building an interactive component for our documentation like so:

# Servers

Thanks to [AngrySnout](https://github.com/AngrySnout/SauerTracker) we have excellent statistics for the game.

<div id="server">
    <ul>
        <li v-for="server in servers" :key="server.description"> {{ server.descriptionStyled }} </li>
    </ul>
</div>

<script>
  const API_URL = "https://tomaten.sauertracker.net/api/servers"

  new Vue({
    el: '#server',
    data: () => ({
        servers: []
    }),
    async mounted {}
        console.log("HEY")
        const response = await fetch(API_URL);
        this.servers = await response.json(); 
    }
  })
</script>

However when loading the page the content quickly flashes before getting “rendered away”. I have no idea what sorcery is going on behind the scenes but my best bet is that it’s an unsupported feature.

Steps to reproduce

(see above)

What is current behaviour

(see above)

What is the expected behaviour

The app that is rendered on screen should allow for dynamic content.

Other relevant information

  • Bug does still occur when all/other plugins are disabled?

  • Your OS: OSX 10.15.3 (19D76)

  • Browser version: Version 80.0.3987.132 (Official Build) (64-bit)

  • Docsify version: 4.11.2

  • Docsify plugins: search plugin

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Koooooo-7commented, Mar 15, 2020

Actually ,It seems some issues about the Vue supports in docsify. Currently, when u create ur own Vue instance, you will not get the Vue instance in the mounted hook by using this (this directs to the window obj in docsify now).

the Vue instance was covered in this.__EXECUTE_RESULT__. there is showing how we execute script in docsify.

  // Execute script
  if (
    this.config.executeScript !== false &&
    typeof window.Vue !== 'undefined' &&
    !executeScript()
  ) {
    setTimeout(_ => {
      const vueVM = window.__EXECUTE_RESULT__;
      vueVM && vueVM.$destroy && vueVM.$destroy();
      window.__EXECUTE_RESULT__ = new window.Vue().$mount('#main');
    }, 0);
  } else {
    this.config.executeScript && executeScript();
  }

Although, I tried to set the root data in a hack way, it seems not work. I haven’t found a way to resolve it yet, I hope those informations could be helpful.

1reaction
jhildenbiddlecommented, Oct 8, 2020

@Fohlen

Fixed in #1271. The example code you provided has a few issues though. Here’s update code that will work as is:

# Servers

Thanks to [AngrySnout](https://github.com/AngrySnout/SauerTracker) we have excellent statistics for the game.

<div id="server">
    <ul>
        <li v-for="server in servers" :key="server.description"><span v-html="server.descriptionStyled"></span></li>
    </ul>
</div>

<script>
  const API_URL = "https://tomaten.sauertracker.net/api/servers"

  new Vue({
    el: '#server',
    data: () => ({
        servers: []
    }),
    mounted() {
      console.log("HEY")
      fetch(API_URL)
        .then(response => response.json())
        .then(data => this.servers = data)
        .catch(err => console.log(err));
    }
  })
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make your components dynamic in Vue.js
Vue dynamic components enable users to switch between two or more components without routing, and even retain the state of data when switching ......
Read more >
Dynamic & Async Components - Vue.js
Dynamic & Async Components. This page assumes you've already read the Components Basics. Read that first if you are new to components.
Read more >
An Overview of Vue Dynamic Components - LearnVue
Vue Dynamic Components can be an extremely convenient way to make your code both more readable and adaptable. They can simplify several ...
Read more >
Dynamic Components with Vue's 'component' - Telerik
Vue gives us a special component and a directive to approach this type of problem, the <component> component. This special component behaves ...
Read more >
vue.js - VueJS dynamic content - Stack Overflow
My problem is when that List/Form component has actions(view, edit...) to be triggered, how can I trigger them "inside" the component and render ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found