- 給組件綁定的事件為什么無法觸發?
在 Vue 2.0 中,為自定義組件綁定原生事件必須使用 .native 修飾符:
<my-component @click.native="handleClick">Click Me</my-component>
從易用性的角度出發,我們對 Button 組件進行了處理,使它可以監聽 click 事件:
<el-button @click="handleButtonClick">Click Me</el-button>
但是對於其他組件,還是需要添加 .native 修飾符。
2.如何在 Table 組件的每一行添加操作該行數據的按鈕?
使用 Scoped slot 即可:
<el-table-column label="操作">
<template slot-scope="props">
<el-button @click.native="showDetail(props.row)">查看詳情</el-button>
</template>
</el-table-column>
參數 row 即為對應行的數據。
3.Tree 組件的 `render-content` 和 Table 組件的 `render-header` 怎么用?
請閱讀 Vue 文檔 Render Function 的相關內容。注意,使用 JSX 來寫 Render Function 的話,需要安裝 babel-plugin-transform-vue-jsx,並參照其文檔進行配置。
4.所有組件的任意屬性都支持 `.sync` 修飾符嗎?
不是。對於支持 .sync 修飾符的屬性,我們會在文檔的 API 表格中注明。更多 .sync 的用法請查看 Vue 文檔。
