vue 父子组件交互_用于vue组件的交互式Sandox游乐场

vue 父子组件交互

组件夹具 (Component Fixture)

Interactive test fixture for vue component.

Vue组件的交互式测试夹具。

Component is designed to receive any component you want to test as a default slot

组件旨在将要测试的任何组件作为默认插槽接收

<component-fixture>

  <!-- Use the default slot to create the component under test -->
  <component-under-test/>

  <!-- Use this slot to enable edition of props values, Editor is provided by this lib-->
  <Editor slot="control" slot-scope="scope" v-bind="scope"/>

</component-fixture>

组件夹具将自动: (Component-fixture will automatically:)

  • Mirror all the props of the tested component

    镜像测试组件的所有道具

  • Bind this data to the component under-test

    将此数据绑定到被测组件

  • Display all the props in a form so that it is possible to edit them

    以表格形式显示所有道具,以便可以对其进行编辑

特征: (Features:)

  • Respect props type and use custom input for each type

    尊重道具类型并为每种类型使用自定义输入

  • Provide input for objects and function

    提供对象和功能的输入

  • Create v-model binding if needed

    根据需要创建v-model绑定

  • Custom props validation when available

    可用的自定义道具验证

  • Support component with slots

    带有插槽的支撑组件

  • Compatible with hot-reload: automatic update on changes hapening on the tested component

    兼容热重装:自动更新测试组件发生的变化

Example using vue-slider-component:

使用vue-slider-component的示例:

example

使用案例 (Uses cases)

Why would you need such a component?

为什么需要这样的组件?

ComponentFixture is intended to be used only in a test/dev context with two main applications.

ComponentFixture仅打算在具有两个主要应用程序的测试/开发环境中使用。

发现第三方组件 (Discovering third party component)

  • Explore Interactively a component you are willing to use in your application.

    以交互方式浏览您愿意在应用程序中使用的组件。

  • Understand by example what the props role.

    以身作则,了解道具的作用。

  • Quickly identify bugs and limitation on the component.

    快速识别组件上的错误和限制。

测试您创建的组件 (Testing a component you creates)

  • Create an example usage of your component that will update automatically

    创建将自动更新的组件用法示例

  • Interact with the component while you create it.

    在创建组件时与组件进行交互。

  • Easily identify bugs

    轻松识别错误

下一步 (Next steps)

  • [x] Provide a way to default component props

    [x]提供一种默认组件道具的方法

  • [ ] Monkey testing: use randomly generated updates on component props.

    []猴子测试:对组件道具使用随机生成的更新。

This will be provided on next major version.

这将在下一个主要版本中提供。

用法示例 (Example usage)

<component-fixture :defaults="{value: 23}">

  <!-- Use the default slot to create the component under test -->
  <component-under-test></component-under-test>

  <!-- Use this slot to enable edition of props values -->
  <template v-slot:control="scope">
    <editor v-bind="scope"/>
  </template>

</component-fixture>
import { ComponentFixture, Editor } from 'component-fixture'
import "component-fixture/dist/ComponentFixture.css"
import { componentUnderTest } from 'componentUnderTest'

export default {
  components: {
    ComponentFixture,
    componentUnderTest,
    Editor
  }
}

API (API)

插槽 (slots)
  • control slot for the form that will edit the props; editor is provided by this library and provide all the features.

    用于编辑道具的表格的control栏; 该库提供了编辑器,并提供了所有功能。

  • default Slot for the component under test

    被测组件的default插槽

道具 (props)
  • defaults Object (optional)

    defaults Object ( 可选 )

    Object that will be set to default the component under-test props. For example if you want to default the props value with 46, just use: :defaults="{value: 46}"

    将被设置为默认的被测道具的对象。 例如,如果您想将props值默认设置为46,则只需使用:defaults="{value: 46}"

安装 (Installation)

npm install ComponentFixture

项目设置 (Project setup)

npm install

编译和热重装以进行开发 (Compiles and hot-reloads for development)

npm run serve

编译并最小化生产 (Compiles and minifies for production)

npm run build

整理和修复文件 (Lints and fixes files)

npm run lint

运行单元测试 (Run your unit tests)

npm run test:unit

使用生成的文档更新README.md的API部分 (Update the API section of README.md with generated documentation)

npm run doc:build

运行样式指南开发服务器 (Run style guide dev server)

npm run styleguide

生成静态HTML样式指南 (Generate a static HTML style guide)

npm run styleguide:build

翻译自: https://vuejsexamples.com/interactive-sandox-playground-for-vue-components/

vue 父子组件交互

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值