Vue 和 React 语法对比 & polyfill

1. class 类名+布尔值

// vue
//react + classnames [https://www.jianshu.com/p/9cf57787360d] render(){ var btnClass = classNames({ 'btn': true, 'btn-pressed': this.state.isPressed, 'btn-over': !this.state.isPressed && this.state.isHovered }); return ; }

2. css 样式作用域

vue











react + css-modules

// webpack.config.js
modules.exports = {
module: {
  loaders: [
    // ...
    {
      test: /\.css$/,
      loader: "style-loader!css-loader?modules&localIdentName=[path][name]---[local]---[hash:base64:5]"
    },
  ]
}}
// .css
.title {
  color: red;
}
:global(.title) {
  color: green;
}
// .tsx
import React from 'react';
import style from './App.css';

export default () => {
  return (
    

Hello World

); };

你可能感兴趣的:(Vue 和 React 语法对比 & polyfill)