A
A
Alexey Bespalov2019-03-31 13:02:12
Google Chrome
Alexey Bespalov, 2019-03-31 13:02:12

In which function to read bookmarks from chrome when using vue?

I'm making a chrome extension using vue. I need to read bookmarks. They are read asynchronously and always after the application is executed.
I couldn't catch them in lifecycle events. Anyway, if you do console.log(), then the function for getting bookmarks is executed last.
As I understand it, bookmarks must be guaranteed to be read before the vue is created, or the component must be re-rendered when they are read. Tell me how to do it?

export default {
  name: 'App',
  components: {
    BkContener
  },
  data () {
    return {
        bookmarks
    }
  },
    methods: {
    getBookmarks(bookmarkTree) {
                chrome.bookmarks.getTree((bookmarkTree) => {
                    console.log('bookmarks tree -> ' + bookmarkTree);
                    console.log(bookmarkTree);    
            }
    }

  },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2019-03-31
@FreeArcher

I assume you are going to do this:

export default {
  name: 'App',
  components: {
    BkContener
  },
  data () {
    return {
      bookmarks: null
    }
  },
  methods: {
    getBookmarks(bookmarkTree) {
      chrome.bookmarks.getTree((bookmarkTree) => {
        console.log('bookmarks tree -> ' + bookmarkTree);
        console.log(bookmarkTree);
        this.bookmarks = bookmarkTree; // Угадал?
      })
    }
  }
}

Well, hang a directive on the root of the template:
<div v-if="bookmarks">
    <!-- Остальной темплейт -->
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question