首先定义一个组件,再在组件中定义一个用来接收值得属性,我这里定义得是testmsg
<template>
<div>{{testmsg}}</div>
</template>
<script>
export default {
name: "Test",
props:["testmsg"]
}
</script>
<style scoped>
</style>
然后在vue页面中import这个组件,然后使用
import Test from '@/components/Test';
new Vue({
el: '#app',
components: {
'test': Test,
}
})
使用
<test :testmsg="123"></test>
然后成功把值传到组件里了。