背景
我正在使用Material Vue AutoComplete组件在vue应用程序中为我的用户提供TypeAhead功能。
当Chrome浏览器的宽度最小化以检查响应性时,我注意到建议容器的宽度变小但是,建议容器内的文本没有在框中打破。相反,正在显示的句子在屏幕右侧的框中运行。
问题
我无法弄清楚如何添加样式来纠正前面提到的问题。
例
<div class="md-layout md-gutter">
<div class="md-layout-item md-small-size-100">
<md-autocomplete
v-model="currentCustomer"
:md-options="customers"
@md-changed="getCustomers"
@md-opened="getCustomers"
@md-selected="getSelected"
:md-fuzzy-search="false"
>
<label>Search Customers...</label>
<template slot="md-autocomplete-item" slot-scope="{ item, term }">
<md-highlight-text :md-term="term">{{ item.email }}</md-highlight-text>
</template>
<template slot="md-autocomplete-empty" slot-scope="{ term }">
No customers matching "{{ term }}" were found. <a @click="addSearchedCustomer(term)">Create </a>this customer.
</template>
</md-autocomplete>
</div>
特别是当没有搜索结果时,此行会在屏幕外运行,
<template slot="md-autocomplete-empty" slot-scope="{ term }"> No customers matching "{{ term }}" were found. <a @click="addSearchedCustomer(term)">Create </a>this customer.</template>
图像示例
更新我尝试过的
当我使用Chrome开发工具检查自动完成时,我展开div,这就是它的样子,
建议容器部 -
题
看看文档,我似乎无法找到解决这个问题的方法。如何将样式应用于此建议框,以便在屏幕变小时打破文本?
模板化的插槽似乎不响应自动换行样式(但其他样式如颜色可以工作)。
一种方法,有点hacky,是使用<label style="white-space: pre-wrap;">
获得多线标签,并使用指令来设置高度。
模板
<md-autocomplete v-model="value" :md-options="colors">
<label>Color</label>
<template slot="md-autocomplete-item" slot-scope="{ item, term }">
<span class="color" :style="`background-color: ${item.color}`"></span>
<label v-wrapit
style="white-space: pre-wrap;"
>{{item.name}}</label>
</template>
<template slot="md-autocomplete-empty" slot-scope="{ term }">
<label v-wrapit
style="white-space: pre-wrap;"
>No colors matching "{{ term }}" were found</label>
</template>
指示
<script>
export default {
name: 'AutocompleteTemplate',
directives: {
wrapit: {
inserted: function (el, binding, vnode) {
el.style.height = `${el.scrollHeight}px`
el.style.color = 'red'
console.log('el', el.scrollHeight, el.offsetHeight, el)
}
}
},
data: () => ({
value: null,
colors: [
{ name: 'Aqua blue blue blue blue blue', color: '#00ffff' },
{ name: 'Aquamarine blue', color: '#7fffd4' },
]
}),
样式
此样式设置整体列表宽度。它是非范围的,因为菜单出现在<div id="app">
之外
<style>
.md-menu-content {
width: 200px !important;
}
</style>
这是一个可以玩的CodeSandbox。