A
A
andreyAmaterasu2020-07-17 16:40:05
Vue.js
andreyAmaterasu, 2020-07-17 16:40:05

How to add a component to Vue Router?

I am working on a Django web application, I connected Vue.js to the templates. In this case, a single-page application, when you click on the button, the page content should change. The documentation states that you can specify a file as a template. Is it possible to specify an html file so that when the button is clicked, the contents of the html file are rendered, if so, how can this be done? 5f11a8b6083e7013432299.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Dyomin, 2020-07-20
@Alkhipce

1. First you need to install html-loaderand configure Webpack:
yarn add html-loader | npm install html-loader

{
    test: /\.(html)$/,
    exclude: /(node_modules)/,
    use: {
      loader: "html-loader"
    }
}

2. Import .htmlthe file into the router.
import Destination from '/path/to/destination.html'

3. Now you can use the .htmlfile as a template.
{
  path: '/destination',
  mode: history,
  name: 'destination',
  component: { template: Destination }
}

Answer from Stack Overflow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question