vue.js - 无法在 vue 组件中导入故事
问题描述
我制作了一个看起来像(FilterCheckbox.js)的故事组件:
export default {
name: 'filter-checkbox',
props: ['options'],
data() {
return {
text: this.$props.options
}
},
watch: {
options: function () {
this.text = this.$props.options;
}
},
template: `
<label class="pure-material-checkbox">
<input class="filterAllInput" type="checkbox" @click="onChange">
<span> {{text}} </span>
</label>
`,
methods: {
onChange() {
this.$emit('change');
},
},
};
它是一个带有文本和自己风格的复选框。现在我想在一个看起来像这样的组件中使用它(Filters.vue):
<template>
<div>
<filter-checkbox @change="onChangeWhenFilterIsChoosen()" :options="options"></filter-checkbox>
</div>
</template>
<script>
import FilterCheckbox from './../../stories/FilterCheckbox';
name: 'Filters',
components: { FilterCheckbox },
data: () => ({
options: 'test text'
}),
methods: {
onChangeWhenFilterIsChoosen: function () {
}
},
</script>
不知何故,导入不起作用,故事组件没有显示在我的其他组件中。我究竟做错了什么?
新: 我现在制作了一个名为:1-Filter.stories.js 的 stories.js:
import { action } from '@storybook/addon-actions';
import FilterCheckbox from './FilterCheckbox';
export default {
title: 'Checkbox',
};
export const text = () => ({
components: { FilterCheckbox },
data() {
return {
options: '12 Liter'
}
},
template: '<filter-checkbox @change="action" :options="options">
</filter-checkbox>',
methods: { action: action('Changed') },
});
那就是很好地实现了过滤器复选框。但仍然无法在其他组件中工作。
解决方案
请使用此更新您的Filters
组件;
<script>
import FilterCheckbox from './../../stories/FilterCheckbox';
export default {
name: 'filters',
components: { filterCheckbox: FilterCheckbox },
data: () => ({
options: 'test text'
}),
methods: {
onChangeWhenFilterIsChoosen: function () {
//
}
},
}
</script>
推荐阅读
- php - 表单数据未使用 laravel 5.4 版本提交到数据库
- reactjs - 开玩笑:测试套件无法运行错误:未提供消息
- javascript - 为什么 mysqljs/mysql 的 .query 回调访问在其块之外定义的变量?
- python - 如何将 pandas DataFrame 的列解压缩为多个变量
- node.js - 在 nodemon 中更改时运行脚本
- python - 如何分解熊猫中的数据?
- android - Firebase:如何使用 emp_id 进行身份验证
- rust - 如何在 Actix-web 的 Future 中访问 HttpRequest 数据?
- python - 缩写字符串中的单词以符合最大长度
- android - 在 Unity 中禁用 Cardboard 的头部跟踪