Giter Club home page Giter Club logo

Comments (5)

ItsRyanWu avatar ItsRyanWu commented on May 18, 2024

其实没有必要这么痛苦的采用目前的解决方式,Vue 有几种在 template 中原生支持的写法来帮你替换掉把 class name 写在 computed 里的需求。
第一种:

<vue-component :class="type === 'news' ? 'w-[220rpx]' : 'w-[340rpx]'"/>

第二种

<vue-component :class="{
  'w-[220rpx]': type === 'news',
  'w-[340rpx]': type !== 'news'
}"/>

本插件对这两种情况都做了兼容性处理,所以你可以优先考虑这两种写法。

至于到底能不能对 computed 甚至 ref 一并做兼容处理,我觉得逻辑上是可以的,但从性能上来说,兼容这两种 edge case 将会对性能造成很大的牺牲。因为插件本来只需要解析 template 部分的 AST 现在为了兼容 edge case 需要解析所有的 script,一方面有限的计算资源会被浪费,另一方面容易“误伤” script block 里的非 Tailwind 变量,会把本来并非用在 Tailwind CSS 中的字符串转译,造成程序 crash 或 bug 都是可能的。
所以我目前并没有打算对 computed 的值做兼容,如果有很多人都有这个需求的话,我或许会考虑在未来让开发者手动在 computed 字符串中加入 flag 来向插件示意该字符串需要被转译。

from mini-program-tailwind.

chasonma avatar chasonma commented on May 18, 2024

其实没有必要这么痛苦的采用目前的解决方式,Vue 有几种在 template 中原生支持的写法来帮你替换掉把 class name 写在 computed 里的需求。 第一种:

<vue-component :class="type === 'news' ? 'w-[220rpx]' : 'w-[340rpx]'"/>

第二种

<vue-component :class="{
  'w-[220rpx]': type === 'news',
  'w-[340rpx]': type !== 'news'
}"/>

本插件对这两种情况都做了兼容性处理,所以你可以优先考虑这两种写法。

至于到底能不能对 computed 甚至 ref 一并做兼容处理,我觉得逻辑上是可以的,但从性能上来说,兼容这两种 edge case 将会对性能造成很大的牺牲。因为插件本来只需要解析 template 部分的 AST 现在为了兼容 edge case 需要解析所有的 script,一方面有限的计算资源会被浪费,另一方面容易“误伤” script block 里的非 Tailwind 变量,会把本来并非用在 Tailwind CSS 中的字符串转译,造成程序 crash 或 bug 都是可能的。 所以我目前并没有打算对 computed 的值做兼容,如果有很多人都有这个需求的话,我或许会考虑在未来让开发者手动在 computed 字符串中加入 flag 来向插件示意该字符串需要被转译。

是的,目前简单的类名控制也是通过你所举例的方式进行处理,只是非不得已需要使用到 computed 进行处理的时候就会出现这个问题,目前我是在业务里封装了一个函数对这些类名进行了转换。

from mini-program-tailwind.

ItsRyanWu avatar ItsRyanWu commented on May 18, 2024

这么说的话,或许我可以暴露一个最小化的处理方法,目前暴露的方法比如 handleTemplate 还不是最小化的,应该新增暴露一个 handleTemplateToken 来让开发者自己在 computed 这种场景中自由使用。

const className = handleTemplateToken('w-[220rpx]') // return 'w--220rpx-'

from mini-program-tailwind.

chasonma avatar chasonma commented on May 18, 2024

可以的,这种场景交给开发者自己处理没毛病。

from mini-program-tailwind.

ItsRyanWu avatar ItsRyanWu commented on May 18, 2024

我这周更新一下这个方法

from mini-program-tailwind.

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.