javascript - 将数据从一个组件发送到另一个 Vuejs
问题描述
这是我的表格组件。
<b-table
class="table table-striped"
id="my-table"
:items="items"
:per-page="perPage"
:current-page="currentPage"
:fields="fields"
@row-clicked="test"
lg
></b-table>
同一组件上的方法:
methods: {
test(){
console.log('test')
this.$emit('rowClick',"heyoooooooo")
}
},
父组件:
<ClientTable :fields="fields" :items="rows" :sortBy="sortBy" :sortDesc="sortDesc" @rowClicked="Callme()"/>
父方法:
methods: {
Callme(e){
console.log('hee')
}
},
我对 VueJS 真的很陌生,我偶然发现了 Emit 我想知道为什么我的代码不起作用,没有任何控制台。
谢谢
解决方案
我重新创建了您的问题,并且效果很好。
Vue.config.devtools = false
Vue.config.productionTip = false
Vue.component('client-table', {
props: ['items'],
methods: {
test(){
this.$emit('row-clicked',"heyoooooooo")
}
},
template: `
<b-table
class="table table-striped"
:items="items"
lg
@row-clicked="test"
></b-table>
`
})
new Vue({
el: "#app",
data: {
rows: [
{ 'heading 1': 'table cell', 'heading 2': 'table cell', 'heading 3': 'table cell' },
{ 'heading 1': 'table cell', 'heading 2': 'table cell', 'heading 3': 'table cell' },
{ 'heading 1': 'table cell', 'heading 2': 'table cell', 'heading 3': 'table cell' },
]
},
methods: {
Callme (e) {
console.log(e)
}
}
})
<link
type="text/css"
rel="stylesheet"
href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css"
/>
<link
type="text/css"
rel="stylesheet"
href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"
/>
<div id="app">
<client-table
:items="rows"
@row-clicked="Callme">
</client-table>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.0.0-rc.28/dist/bootstrap-vue.js"></script>
推荐阅读
- mysql - 如何在 MySQL Group By 查询中找到唯一值?
- git - Git,修复文件名和路径,编码
- swift - Bitrise 错误:cocoapods 项目-工作区映射错误
- node.js - 在 C 盘(电子)中创建本地文件
- sql-server - 数据库导出在 Microsoft SQL Server 2014 中出现错误
- customization - 如何绕过 Azure AD B2C 中“编辑配置文件”策略中的 IdP 选择?
- unity3d - 统一检查 Daydream 兼容性
- hadoop - 针对 S3 的 oozie fs 操作未更新 S3 存储的清单(DynamoDB 元存储 - emrfs 不同步)中的密钥
- vue.js - b-nav-form 不会与垂直导航栏堆叠,而是水平呈现
- python - Python matplotlib如何将颜色映射到饼图中的“x值”