A
A
Andrey2017-09-13 18:25:24
Vue.js
Andrey, 2017-09-13 18:25:24

Why are parameters not being passed to the vue component?

main.js

import Vue from 'vue'
import store from './store'

new Vue({
  el: '#productList',
  store,
  template: '<span> msg: {{msg}}</span>',
  props: ['msg']
})

index.html only outputs msg as a result: how to pass a parameter to a component? I use vue-cli to build. UPD: example https://www.webpackbin.com/bins/-KtvyvDYFoQ2xxX0xAsZ
<div id="productList" msg="сообщение"></div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Sokolov, 2017-09-13
@flx12

Because you are confusing the concepts of a component and an application. In your case, you need to do something like this:
main.js

import Vue from 'vue'
import store from './store'

Vue.component('productList', {
  template: '<span> msg: {{msg}}</span>',
  props: ['msg']
});

var app = new Vue({
  el: '#app',
  store,
})

index.html:
<div id="app">
  <product-list msg="message"></product-list>
</div>

Those. You instantiate Vue once and then add components to it.

A
Anton Anton, 2017-09-13
@Fragster

Because in the example, it's not a component, but an application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question