I want to assign some attributes and classes to the children VNode
through data
object. That just works. But during my Vue.js investigation, I have not seen such pattern in use, that's why I don't think it's good idea to modify children VNode
's.
But that approach sometimes comes in handy – for example I want to assign to all the buttons in default slot the aria-label
attribute.
See example below, using default stateful components:
Vue.component('child', {
template: '<div>My role …
Run Code Online (Sandbox Code Playgroud)我已经使用 Vue.js 和 express.js 构建了一个应用程序。目前我必须打开两个终端窗口并npm run serve
在一个和npm start
另一个中运行。我想让服务器在 Vue.js 应用程序在同一终端中构建后运行。我在这篇文章中读到,我可以通过将两个package.json
脚本链接在一起来运行这两个脚本,但我一生都无法弄清楚如何运行。我的项目结构如下:
??? project
??? _frontend
| ??? package.json
??? backend
| ??? package.json
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
1st try - "serve": "vue-cli-service serve && (cd ../server && npm start)"
2nd try - "serve": "vue-cli-service serve && (cd ../server && npm run start)"
3rd try - "serve": "vue-cli-service serve && (cd ../server) && npm start"
Run Code Online (Sandbox Code Playgroud)
Vue.js 应用程序构建并运行得很好,但服务器没有启动。我也尝试在服务器上进行相反的操作,package.json
服务器启动但应用程序未构建。这是由于文件夹设置而我无法完成的事情还是我做错了什么?
是否可以在视图模板中使用三元条件来返回 HTML,类似于 Reacts 渲染函数?
<some-vue-component :someProp="someVal" />
// some-vue-component template file
{{someProp == true ? <h1>Hello</h1> : <h1>Bye</h1>}}
This doesnt seem to work
Run Code Online (Sandbox Code Playgroud)
编辑:我需要使用v-if
吗?
// some-vue-component template file
<div>
<div v-if="someProp === true">
<h1>Hello</h1>
</div>
<div v-else>
<h1>Bye</h1>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 在一个动作中,我正在做:
this.$cookies.set("token", response.token, "7d");
this.$cookies.set("UserId", response.UserId, "7d");
Run Code Online (Sandbox Code Playgroud)
但唉$cookies
没有定义。
最近,我一直在构建一个使用大量独立 Vuex 模块的大型应用程序。让我们来看看其中之一(例如support-chat
)。支持聊天位于它自己的单独页面上,在初始应用程序加载时使用此模块污染商店是多余的。我的目标是在加载页面时动态注册此模块。所以我的问题是 – 我应该在哪里、何时以及如何注册该模块?
我最终beforeCreate
在页面组件的钩子中注册了这个模块:
import supportChatModule from '@/vuex/modules/support-chat'
// ...
beforeCreate() {
this.$store.registerModule('support-chat', supportChatModule, { preserveState: process.client })
},
beforeDestroy() {
this.$store.unregisterModule('support-chat')
}
// ...
Run Code Online (Sandbox Code Playgroud)
这种方法有什么缺陷?
如果您能分享您解决该问题的方法,那就太好了。
我想从Vuetify扩展面板中删除阴影。当前,它看起来像这样:
我的代码如下所示:
<v-layout wrap justify-space-between>
<v-flex xs12 pb-1>
<v-card>
<v-container pa-2>
<v-expansion-panel expand pa-0>
<v-expansion-panel-content>
<template v-slot:header>
<div>
{{ $t("var1") }}
</div>
</template>
<v-layout row wrap>
<v-flex xs12>
<v-text-field
class="right-input"
:label="$t('var2')"
value="600.00"
suffix="$"
disabled
flat
></v-text-field>
</v-flex>
</v-layout>
</v-expansion-panel-content>
</v-expansion-panel>
</v-container>
</v-card>
</v-flex>
</v-layout>
Run Code Online (Sandbox Code Playgroud)
是否可以从扩展面板上去除阴影?我尝试将“扁平”添加到标签,但无法解决。我的目标是,在扩展的同时,它看起来像是平面卡。谢谢!:)
我用vue create
命令创建了一个项目,更改了目录并使用了npm run serve
命令。错误出现了。
我尝试更新npm
软件包,但没有用。
error in ./src/main.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
BrowserslistError: [BABEL] C:\Users\peter\test\src\main.js: C:\Users\peter\test contains both browserslist and package.json with browsers (While processing: "C:\\Users\\peter\\test\\node_modules\\@vue\\babel-preset-app\\index.js")
at C:\Users\peter\test\node_modules\browserslist\node.js:263:15
at eachParent (C:\Users\peter\test\node_modules\browserslist\node.js:47:18)
at Object.findConfig (C:\Users\peter\test\node_modules\browserslist\node.js:246:20)
at Function.loadConfig (C:\Users\peter\test\node_modules\browserslist\node.js:177:37)
at browserslist (C:\Users\peter\test\node_modules\browserslist\index.js:333:31)
at getTargets (C:\Users\peter\test\node_modules\@babel\preset-env\lib\targets-parser.js:184:50)
at getPolyfills (C:\Users\peter\test\node_modules\@vue\babel-preset-app\index.js:20:26)
at module.exports (C:\Users\peter\test\node_modules\@vue\babel-preset-app\index.js:106:17)
at loadDescriptor (C:\Users\peter\test\node_modules\@babel\core\lib\config\full.js:165:14)
at cachedFunction (C:\Users\peter\test\node_modules\@babel\core\lib\config\caching.js:33:19)
at loadPresetDescriptor (C:\Users\peter\test\node_modules\@babel\core\lib\config\full.js:235:63)
at config.presets.reduce (C:\Users\peter\test\node_modules\@babel\core\lib\config\full.js:77:21)
at Array.reduce (<anonymous>)
at recurseDescriptors (C:\Users\peter\test\node_modules\@babel\core\lib\config\full.js:74:38)
at loadFullConfig (C:\Users\peter\test\node_modules\@babel\core\lib\config\full.js:108:6)
at process.nextTick (C:\Users\peter\test\node_modules\@babel\core\lib\transform.js:28:33) …
Run Code Online (Sandbox Code Playgroud) 我有一个抽屉式导航不将内容推到一边从移动它mini.variant
来opened
。
<v-navigation-drawer
class="chatbar--gradient"
app
right
:mini-variant.sync="closed"
mini-variant-width="70"
width="250px"
></v-navigation-drawer>
Run Code Online (Sandbox Code Playgroud)
App.vue
:
<v-app dark>
<app-navbar></app-navbar>
<navigation-bar></navigation-bar>
<v-slide-y-transition>
<chat-sidebar></chat-sidebar>**
<!-- THIS IS THE MODAL FROM ABOVE -->
**
</v-slide-y-transition>
<v-content>
<keep-alive>
<transition name="fade">
<router-view :key="$route.fullPath" />
</transition>
</keep-alive>
<display-name-entry-modal></display-name-entry-modal>
</v-content>
<v-footer v-if="$vuetify.breakpoint.smAndUp" tile padless height="3px" app class="pageFooter"></v-footer>
<bottom-nav v-if="$vuetify.breakpoint.smAndDown"></bottom-nav>
</v-app>
Run Code Online (Sandbox Code Playgroud) 问题:无法在单元测试中以编程方式触发 Vue-Select3 项目下拉选择。
我已经尝试使用vue-test-utils
和@testing-library/vue
以及在浏览器中以编程方式触发点击事件以强制选择列表项。然而,这些都没有奏效。我设法触发选择的唯一方法是获取 VueSelect 实例并发出“输入”事件。我还尝试在下拉容器等上触发不同的事件。
// Failed
// testing-library
const dropdownItem = getAllByTestId('dropdown-item')
fireEvent.click(dropdownItem[0])
// test-utils
wrapper.find('[data-testid=dropdown-item]').trigger('click')
// In browser
document.querySelectorAll('.vs__dropdown-item')[0].click()
// Success
wrapper.find(VueSelect).vm.$emit('input', payload)
Run Code Online (Sandbox Code Playgroud)
当前结果:当点击事件被触发时,什么也不会发生。 预期结果:当点击事件被触发时,Vue-Select 应该选择该项目并发出 'input' 事件。
通常我在要使用该函数的组件中创建该函数,但是,我开始需要在两个或更多组件中使用某个函数,这意味着现在我必须将其复制并放置在其他组件。这显然不是最佳的,所以我想知道应该将这些函数放在哪里。为了向您展示通用实用函数的含义,我将在此处添加一个:
winrate(wins, losses) {
let games = wins + losses
return Math.round(wins * 100 / games) + '%'
}
Run Code Online (Sandbox Code Playgroud)
没什么特别的,只是取胜负,然后返回胜率。
我正在使用 Vuex,实际上我可以将它们放在 Vuex 商店中,但是,我不确定这是否是最好的选择,所以这就是我问你们的原因。
vue.js ×10
javascript ×4
vuetify.js ×2
vuex ×2
express ×1
jestjs ×1
npm ×1
npm-scripts ×1
nuxt.js ×1
store ×1
unit-testing ×1
vue-cli ×1
vue-cookies ×1
vue-select ×1
vuejs2 ×1