javascript - 基于对象构建可重用的 Vue 组件
问题描述
我正在尝试构建一个基于 DHTMLX Grid 的 Vue 可重用组件,该组件是从一个对象初始化的,但问题是我正在尝试构建一个通用组件,目的是在单个页面中多次使用它在该组件内部,我有一个名为 grid 的对象声明,它是我用于创建网格的对象。
声明如下所示:
this.grid = new GridDHX(idGrid, {
columns: X,
height: X,
selection: "simple",
data: X,
});
但是当我多次初始化组件时,因为对象名称是相同的在每次初始化中我都会遇到这些错误:
Method "grid" has type "object" in the component definition. Did you reference the function correctly?
Method "grid" has already been defined as a data property.
基本上问题是组件内部对象的名称被多次重用,所以就像它无法检测到哪个组件是哪个。
如何在没有这些问题的情况下创建可重用的 Vue 组件?
解决方案
在这里,您可以查看 Vue 的 DHX Grid 包装器示例
https://github.com/DHTMLX/vue-suite-demo/blob/master/src/components/grid/GridBase.vue
并在这里进行现场演示
https://dhtmlx.github.io/vue-suite-demo/?path=/story/grid--base
import { Grid as GridDHX } from "dhx-suite";
export default {
name: "GridBase",
data: () => ({
grid: null,
}),
mounted() {
this.grid = new GridDHX(this.$refs.grid, {
推荐阅读
- random - 如何使用 Rust 中的 rand crate 输入整数种子以生成随机数?
- python - 生成具有最大连续元素差异的所有组合
- c# - 登录到使用重定向的网页
- php - 在特定页面执行功能
- swift - 比较从两个字符串计算的值
- python - PiCamera - 如何将“rgb”格式的 np.array 捕获保存到文件中?
- sql - PostgreSQL 随机子查询
- javascript - 我应该使用哪个功能?.toDataURL() 还是 .toBlob()?
- android - Android VideoView 不会在树莓派上播放视频
- google-apps-script - Ebay API:ActiveInventoryReport 数据