如果插槽模板中有一些引用,我如何从组件访问这些引用?例如:
<template>
<div>
<slot></slot>
</div>
</template>
<script>
export default {
created() {
console.log(this.$refs.ele)
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
<template>
<v-component>
<template slot-scope="props">
<h1 ref="ele"></h1>
</template>
</v-component>
</template>
<script>
import VComponent from './v-component
export default {
components: { VComponent }
}
</script>
Run Code Online (Sandbox Code Playgroud)
v-compoent.vue 输出中的 this.$refs.ele 未定义。我的问题是如何获得这个元素?
我在本地环境开发vue项目时(运行npm run dev命令),第一页加载没有报错。但是当我点击刷新按钮时,控制台输出“SyntaxError:预期表达式,得到'<'”错误,并且热重载不起作用。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>kmf</title>
</head>
<body>
<div id="app">
</div>
<!-- built files will be auto injected -->
<script type="text/javascript" src="app.js"></script></body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是如果我运行 npm run build 并将文件上传到服务器。不输出此错误。有谁知道问题出在哪里?
我正在使用 TypeScript 开发一个 Vue 应用程序。我创建了一个 mixin(如下所示global.mixin.js),并将其注册为Vue.mixin()(main.ts如下所示)。
import { mathHttp, engHttp } from '@/common/js/http'
export default {
methods: {
wechatShare(config) {
config.imgUrl = config.imgUrl
mathHttp.get('/wechat/config', {
url: encodeURIComponent(window.location.href),
}).then((data) => {
wx.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.noncestr,
signature: data.signature,
jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'],
})
})
wx.ready(() => {
wx.updateAppMessageShareData(config)
wx.updateTimelineShareData(config)
})
},
},
}
Run Code Online (Sandbox Code Playgroud)
我注册了全局 mixin Vue.mixin():
import { mathHttp, engHttp } from '@/common/js/http'
export default {
methods: {
wechatShare(config) …Run Code Online (Sandbox Code Playgroud) 我在自己的 Ubuntu 服务器上安装了 mongodb 软件,并得到了这样的 mongo 字符串mongodb://xxx:pass@42.212.159.109:27017,当我在本地终端中键入该字符串并使用时mongosh mongodb://xxx:pass@42.212.159.109:27017,它工作正常并且连接成功。但是当我在 Nestjs 项目中使用这个 mongodb 字符串时,当我运行时npm run start,终端输出MongoServerError: Authentication failed.
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
const username = configService.get('MONGO_USER');
const password = configService.get('MONGO_PASS');
const database = configService.get('MONGO_DATABASE');
const host = configService.get('MONGO_HOST');
const port = configService.get('MONGO_PORT');
return {
type: 'mongodb',
host,
port,
username,
password,
database,
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
};
},
Run Code Online (Sandbox Code Playgroud)
mongodb版本是4.1.3,TypeOrm版本是0.2.38。有谁知道问题是什么以及如何解决?感谢你。
我已经为电话编写了一个自定义验证器并像这样使用它
<template>
<input type="text" name="username" class="username" v-validate="'required|email|phone'">
</template>
<script>
import { MobileValidate } from '@/validates/MobileValidates'
Validator.extend('phone', MobileValidate);
</script>
Run Code Online (Sandbox Code Playgroud)
const MOBILEREG = /^((1[3578][0-9])+\d{8})$/;
export const MobileValidate = {
getMessage(field, args) {
return 'phone is wrong';
},
validate(value, args) {
console.log(MOBILEREG.test(value), value)
return MOBILEREG.test(value);
}
};
Run Code Online (Sandbox Code Playgroud)
我想验证用户名是电子邮件还是电话号码,但似乎不起作用。我怎么解决这个问题?
例如:
'abcjkjokabckjk'.replace('/(abc)/g',...)
Run Code Online (Sandbox Code Playgroud)
如果我想替换指定位置'abc',我能做什么?
像这样:

例如:
response()->json(['error' => 'invalid', 401]);
response()->json(['success' => 'success', 200]);
Run Code Online (Sandbox Code Playgroud)
这两种方式都是响应200.如果我想在成功时返回200,而在错误发生时返回401.我怎样才能实现这一点.
我已经阅读了几个关于闭包的教程.一些教程有一些关于执行上下文的信息.我很困惑,执行上下文和闭包看起来是一回事.有人能解释一下吗?
例如,如果我有这样的对象:
let obj = { a: 1, b: 2 }
let { a, b } = obj;
console.log(a, b); // output 1, 2
Run Code Online (Sandbox Code Playgroud)
但是如果a和b被初始化,就像这样:
let obj = { a: 1, b: 2 };
let a = 3, b = 4;
{ a, b } = obj;
console.log(a, b); // error
Run Code Online (Sandbox Code Playgroud)
它们之间有什么区别,为什么第二个输出错误?
javascript ×4
vue.js ×4
vuejs2 ×3
ecmascript-6 ×1
express ×1
laravel ×1
laravel-5 ×1
mongodb ×1
nestjs ×1
regex ×1
typeorm ×1
typescript ×1
vee-validate ×1
vue-cli ×1
webpack ×1