[Vuejs]-Filtering a stack trace array in vuejs

1👍

Maybe something like following snippet:

const app = Vue.createApp({
  data() {
    return {
      st: `Exception in thread "main" java.lang.NullPointerException
        at com.example.myproject.Book.getTitle(Book.java:16)
        at com.example.myproject.Author.getBookTitles(Author.java:25)
        at com.example.myproject.Bootstrap.main(Bootstrap.java:14)`,
      expanded: false
    };
  },
  computed: {
    firstLine() {
      return this.st.split('\n')[0]
    },
    allLines() {
      return this.st.split('\n').filter((item, idx) => idx !== 0).toString()
    }
  },
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
  {{ firstLine }}
  <button @click="expanded = !expanded">all</button>
  <div v-if="expanded">{{ allLines }}</div>
</div>

Leave a comment