【发布时间】:2019-04-05 16:12:27
【问题描述】:
我有一个基本的示例组件设置,它像这样绑定到一个 Vue 实例
<template>
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Example Component</div>
<div class="panel-body">
{{ msg }}
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data : function(){
return{
msg : "Hello"
}
},
mounted() {
console.log('Component mounted.')
}
}
</script>
这是我的app.js 文件
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('example-component', require('./components/ExampleComponent.vue'));
var firstComponent = new Vue({
el: '#app'
});
这是我的HTML
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<div id="app">
<example-component></example-component>
</div>
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
我现在如何更改msg 的值?我在任何地方都没有提到该组件?我该怎么做?
这可能吗?
var ex = Vue.component('example-component', require('./components/ExampleComponent.vue'));
ex.data = "new Value";
【问题讨论】:
-
如果记得正确的
<example-component :message="Hello"></example-component>并添加message到道具
标签: javascript vue.js vuejs2