我正在尝试学习 ES6 导入和导出,但我遇到了一个错误,无法导入我的模块。我也试过import .. from 'add.js'没有 ./ 但仍然没有运气。
未捕获的语法错误:请求的模块“./add.js”不提供名为“add”的导出
我的文件夹结构是这样的
C:\xampp\htdocs\es6\import.export\
- index.html
- app.js
- add.js
Run Code Online (Sandbox Code Playgroud)
索引.html
<html>
<head>
<script type="module" src="app.js"></script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
应用程序.js
import { add } from './add.js'
console.log(add(2,3))
Run Code Online (Sandbox Code Playgroud)
添加.js
export default function add (a, b) {
// export default function (a, b) { <-- does not work either, same error
return a + b;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Vue 3 中观看道具,但奇怪的是,当我解构它时,观察者不起作用。但没有解构它按预期工作。我在这里缺少什么?
PS 我正在使用 Vue 3 + Vite
这不起作用
export default {
props: {
modelValue: {
type: Boolean,
default: false,
},
},
setup({ modelValue }, context)
{
watch(() => modelValue, (newValue, oldValue) => {
console.log(newValue)
})
},
}
Run Code Online (Sandbox Code Playgroud)
但如果我不解构它,它就会起作用
setup(props, context) {
watch(() => props.modelValue, (newValue, oldValue) => {
console.log(newValue)
})
}
Run Code Online (Sandbox Code Playgroud) 我正在Vue中创建一个简单的开关切换组件,该组件具有v模型和@updated。但是当用户切换开关时,我似乎无法更改模型。首先,我遇到了错误,以避免直接更改道具。但是现在我又遇到了另一个错误。
[Vue警告]:已将计算属性“ isSwitchOn”分配给它,但没有设置器。
该组件旨在像这样使用
<iswitch v-model="switchGender" @updated="handleUpdatedGender" />
Run Code Online (Sandbox Code Playgroud)
这是组件本身
export default {
template: `
<span
@click="toggleSwitch"
:class="{ active: isSwitchOn }">
<span class="toggle-knob"></span>
</span>
`,
props: ['value'],
methods:
{
toggleSwitch()
{
this.isSwitchOn = !this.isSwitchOn
this.$emit('input', this.isSwitchOn)
this.$emit('updated')
}
},
computed:
{
isSwitchOn()
{
return this.value
}
},
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ES6 模块导入 .css 文件,但出现错误。甚至可以在不使用捆绑器或转译器(如 webpack)的情况下导入 css 文件吗?
加载模块脚本失败:服务器以“text/css”的非 JavaScript MIME 类型响应
<html>
<body>
<div id="app">
{{ msg }}
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="module">
import './style.css'
new Vue({
el: '#app',
data: {
msg: 'Hello World!'
}
})
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我使用 npm -install jquery 安装了 jQuery,它在我的项目中创建了一个 node_modules 文件夹,其中包含 jquery。但是当我尝试使用 ES6 import 导入它时,它给了我一个错误。
我不想使用 Webpack 或 require() 并且必须编译它……其他任何东西都只是普通的 ES6。
我总是收到这个错误
未捕获的语法错误:请求的模块“./node_modules/jquery/dist/jquery.min.js”不提供名为“$”的导出
或者
未捕获的语法错误:请求的模块“./node_modules/jquery/src/jquery.js”不提供名为“$”的导出
项目结构
.
??? index.html
??? app.js
??? node_modules/
? ??? jquery/
? ? ??? dist/
? ? ? ??? jquery.js
? ? ? ??? jquery.min.js
? ? ??? src/
? ? ? ??? jquery.js
??? package.json
Run Code Online (Sandbox Code Playgroud)
应用程序.js
import { $ } from './node_modules/jquery/dist/jquery.min.js'; // <-- does not work
import { $ } from './node_modules/jquery/src/jquery.js'; // <-- does not …Run Code Online (Sandbox Code Playgroud) 我有一个简单的 Laravel 应用程序,其中 Nginx、PHP 和 MySQL 都在自己的容器中。我不明白的是:
为什么我需要为我的 Nginx 和 PHP 安装卷?PHP 不是只是一种编程语言而不是服务器吗?
另外,对于生产,我需要将我的 src 复制到/var/www/html,但是我需要为 Nginx 和 PHP 执行此操作吗?或者只适用于 Nginx?
这是我的docker-compose-dev.yml文件:
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginxcontainer
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysqlcontainer
restart: unless-stopped
tty: true
ports:
- "4306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql …Run Code Online (Sandbox Code Playgroud) I am using vue.js in this case but I guess it would apply in plain JS too. The problem is that when I am in a function that is in another function I am having to call variables by their full path like - Object.variable instead of this.variable. Is there a way to use this.timer, this.pages instead of TVComponent.pages etc.
const TVComponent = new Vue ({
el: '.tvContent',
data:
{
current_page: 0,
timer: 0,
pages: [
{ page: '/', interval: …Run Code Online (Sandbox Code Playgroud) 我正在使用 Vuetify 菜单(作为弹出窗口),在文档中它说 auto 属性将菜单项居中,但由于某种原因,菜单项没有水平居中(在本例中它是一张卡片)。
我是否在这里遗漏了一些我没有注意到的重要内容?
从文档中
auto - 将列表置于所选元素的中心
<v-menu
v-model="menu"
:close-on-content-click="false"
auto
offset-y>
Run Code Online (Sandbox Code Playgroud)
以下是 codpen 上的完整示例:https://codepen.io/anon/pen/aMJOaY ?&editable=true&editors=101
我正在实现 Vue.js 动态组件,但我似乎无法弄清楚如何仅在获取数据时才显示该组件。在此之前,它应该显示旧组件。
场景是这样的。当页面加载时,它应该显示 Home 组件。然后我点击“显示帖子”。在 Posts 组件获取它的帖子之前,什么都不应该发生。然后它应该显示 Posts 组件。我不想显示任何加载。
我可以在我的 Home 组件中获取帖子,但我认为 Posts 组件应该对此负责。此外,如果我有很多组件,我不想在我的 Home 组件中获取它们的所有数据。他们应该获取自己的数据(我认为)。这是可能的吗?
主页.js
import Home from './home.js'
import Posts from './posts.js'
export default {
template: `
<div>
<a @click="showPosts">Show posts</a>
<component :is="currentComponent" />
</div>
`,
methods:
{
showPosts()
{
// Do this ONLY after the Posts component has fetched it's data... not immediately...
this.currentComponent = Posts
}
},
data:
{
currentComponent: Home
},
}
Run Code Online (Sandbox Code Playgroud)
帖子.js
export default {
template: `
<div>
<div v-for="post in posts">{{ …Run Code Online (Sandbox Code Playgroud) 作为一名开发人员,我对 HTTP/3.0 的下一个版本感到非常兴奋。前段时间我注意到,当我打开 Google.com 时,我可以在 Devtools > Network 中看到该协议显示为 Quic。但现在当我打开它时,我只看到 h2 。这是为什么?
我还注意到 alt-svc 标头表明该资源也可以快速使用。但它仍然在 h2 上加载。
alt-svc: quic=":443";
Run Code Online (Sandbox Code Playgroud)
我在使用curl时注意到同样的事情,使用的协议是h2而不是h3。但谷歌多年来一直在使用 Quic。为什么会有这样的改变?
curl -v https://www.google.com/
* ALPN, offering h2
* ALPN, offering http/1.1
* ALPN, server accepted to use h2
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
> GET / HTTP/2
> Host: www.google.com
> User-Agent: curl/7.61.1
> Accept: */*
Run Code Online (Sandbox Code Playgroud) javascript ×8
vue.js ×5
ecmascript-6 ×2
containers ×1
css ×1
docker ×1
dockerfile ×1
es6-modules ×1
html ×1
http ×1
jquery ×1
npm ×1
quic ×1
tcp ×1
vuejs3 ×1
vuetify.js ×1