Giter VIP home page Giter VIP logo

Comments (6)

arnoson avatar arnoson commented on May 22, 2024 2

Since Vue 3.3 now supports typed Slots with defineSlots it would be great If you could reconsider this decision. For me, render functions feel were un-vue like. I know there a basic feature of vue, but it feels much more natural, to keep all template related stuff inside <template>. A lot of other vue component libraries support this (primevue, vant, ...). Overall I just like this library better, so having the choice between render functions and slots would make it perfect for me :)

from naive-ui.

07akioni avatar 07akioni commented on May 22, 2024

Dynamic slot name is not a good pattern since it's very unfriendly to typescript. Personally I don't think this is a good API.

Currently vue's slot has no type but if some time later it supports it, the API will cause chaos.

The case you provide is not convicing since it doesn't show template slot is much easier than render function. If you could provide some more convincing examples, I will reopen the issue.

from naive-ui.

yhyzgn avatar yhyzgn commented on May 22, 2024

那为啥官方会报出警告,并建议使用slot方式来提升性能呢?
image

而且使用h函数渲染会导致class等属性无效等问题
单组件自定义还行,多个组件自定义时就更不方便,而且难度不低哦
比如要实现这样de的效果:
image
貌似只能这么写吧:

{
  title: '操作',
  key: 'operation',
  render(row) {
    return [
      h(NButton, {
        text: true,
        onClick: () => {
        },
      }, '编辑'),
      h(NButton, {
        text: true,
        style: {
          marginLeft: '12px',
        },
        onClick: () => {
        },
      }, '删除'),
      h(NButton, {
        text: true,
        style: {
          marginLeft: '12px',
        },
        onClick: () => {
        },
      }, '重置密码'),
    ]
  },
},

from naive-ui.

07akioni avatar 07akioni commented on May 22, 2024

那为啥官方会报出警告,并建议使用slot方式来提升性能呢? image

而且使用h函数渲染会导致class等属性无效等问题 单组件自定义还行,多个组件自定义时就更不方便,而且难度不低哦 比如要实现这样de的效果: image 貌似只能这么写吧:

{
  title: '操作',
  key: 'operation',
  render(row) {
    return [
      h(NButton, {
        text: true,
        onClick: () => {
        },
      }, '编辑'),
      h(NButton, {
        text: true,
        style: {
          marginLeft: '12px',
        },
        onClick: () => {
        },
      }, '删除'),
      h(NButton, {
        text: true,
        style: {
          marginLeft: '12px',
        },
        onClick: () => {
        },
      }, '重置密码'),
    ]
  },
},

可以定义一个组件,包含着三个按钮然后暴露一些属性出来,那样渲染函数写起来会简单一些

from naive-ui.

stylefieber avatar stylefieber commented on May 22, 2024

If you want to use other components in the cell template or / and use template directives, it would be much easier to use with having slots available.

from naive-ui.

fudiwei avatar fudiwei commented on May 22, 2024

I created a project @skit/x.naive-ui based on Naive-UI, enables to use DataTable in template style. Welcome to improve it.

For the scenario proposed by OP, it can be written as:

<x-n-data-table :columns="columns" :data="data">
  <template #renderCell="{ column, rowData, value }">
    <span>{{ column.title }} {{ value }} Custom things</span>
  </template>
</x-n-data-table>

from naive-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.