N
N
NiceScript2018-12-30 21:58:36
Vue.js
NiceScript, 2018-12-30 21:58:36

How to load components in vue depending on server response?

What is available:
1) vue file ( naturally, something is wrong here, please help .. )

<template >
  <div class="app" >
     {{dataArticle}} //подгружаем сюда сгенерированые данные
  </div>
</template>
<script>
import LoadFunctions from '@/services/LoadFunctions'
export default {
  name: 'settings',
  data () {
    return {
      dataArticle:  '' 
    }
  },
  mounted () {
    this.getArticle('10') // хочу получить статью номер 10
  },
  methods: {
    async getArticle (data) { // выполняем функцию из mounted
      const response = await LoadFunctions.getArticle(data) // отправляем запрос 
      this.dataArticle = response.data // получаем данные
    }
  }
}
</script>

2) Send data to the server (file /services/LoadFunctions)
export default {
  getArticle (data) {
    return Api().post('getArticle', data)
  }
}

3) The server processes the request, turns to mongodb looking for the desired article.
return such
data: {
  used_component:  'article_with_video',
  component_data: {
  	header: 'Заголовок',
  	text: 'Текст статьи',
  	video_url: 'http ссылка' 
  } 
}

....
And here I have json problems
, I defined it in the answer,
but how can I load this particular used_component by passing component_data to it?
Happy New Year, toasters)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question