JavaScript/vue.js/error:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
(未显示同一用户的23个中间版本)
第20行: 第20行:
* Unknown custom element: <el-menu> - did you register the component correctly? For recursive components, make sure to provide the "name" option
* Unknown custom element: <el-menu> - did you register the component correctly? For recursive components, make sure to provide the "name" option
*: 耗时 5 个小时,试过多个 webpack 方案,经过仔细爬坑,是因为 vue 与 ejs 不兼容导致的(vue-loader 与 html-webpack-plugin 和 ejs-compiled-loader),将 ejs 解析器 替换回 ejs-loader(vue-loader 与 html-webpack-plugin 和 ejs-loader)即可,但是这样就不能使用 ejs 嵌套标签
*: 耗时 5 个小时,试过多个 webpack 方案,经过仔细爬坑,是因为 vue 与 ejs 不兼容导致的(vue-loader 与 html-webpack-plugin 和 ejs-compiled-loader),将 ejs 解析器 替换回 ejs-loader(vue-loader 与 html-webpack-plugin 和 ejs-loader)即可,但是这样就不能使用 ejs 嵌套标签
*: 更正,并不是 (vue-loader 与 html-webpack-plugin 和 ejs-compiled-loader)不兼容,而是重复引入多个 elementui 导致错误
* Do not use built-in or reserved HTML elements as component id: Header
*: 模板插入到 DOM 中的标签名须能够被 DOM 正确地解析需要避免完全不合法的标签名
* vue.esm.js:628 [Vue warn]: Failed to mount component: template or render function not defined.found in---> <Anonymous> <App> at view/index/app.vue <Root>
*: 路由文件里面改 import Vue from 'vue'; 为 <code>import Vue from 'vue/dist/vue.common.js';</code>
* <router-view> 内容不渲染问题
*: <code><router-view class="index" name="NavMenu"></router-view></code> 改为  <code><router-view></router-view></code>,如果一定使用 name(路由命名),name 要与 router.js 内的组件名称一致,是<code>components</code> 而不是 <code>component</code>。
*: <syntaxhighlight lang="javascript">
export default new Router({
    routes: [
        {
            path: '/',
            components: {NavMenu: NavMenu},
            children:[]
        }
    ]
})</syntaxhighlight>
* [Vue warn]: Invalid prop: type check failed for prop "index". Expected String, got Number.
*: 使用强制类型转换技巧 <code><el-submenu :index="item.id+''"></code> 转换数据类型
* css 样式抽取极其不稳定,只显示 <code>/*# sourceMappingURL=index_page_script.css.map*/</code>。现在遇到的问题是 MiniCssExtractPlugin.loader 可以提取 css 文件打包使用 link 标签插入,或者 vue-style-loader 抽离 vue 文件中的 css 用 style 标签插入<br>
  其中 FixStyleOnlyEntriesPlugin 组件一定要与 MiniCssExtractPlugin 同步使用,不然会把 css 的 js 文件删除,导致 css 文件无法插入文本。
* elementui 更改样式无效,修改 css 标签,去掉 scoped
*: <syntaxhighlight lang="html">
<style lang="scss" rel="stylesheet/scss" scoped></syntaxhighlight>
* Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead
*: <syntaxhighlight lang="html5">
<template>
    <div>
        <router-view name="default"></router-view>
        <router-view name="index_main"></router-view>
        <router-view name="info_main"></router-view>
        <router-view name="list_main"></router-view>
    </div>
</template></syntaxhighlight>
* Vue warn]: Error in render: "TypeError: Cannot read property 'key' of undefi
*: 元素加上v-if 指令,判断这个数组中是否有内容,警告即可解除
*: <syntaxhighlight lang="html5">
<div v-if="BospitalSearchFilters[0]">
            <span class="sub-nav-title" :value="BospitalSearchFilters[0].key">{{BospitalSearchFilters[0].title}}:</span></syntaxhighlight>
* 页面在手机浏览器报错 Failed to load resource: net::ERR_NAME_NOT_RESOLVED
*: axios在部分手机的微信浏览器中无法发起请求
*: 尝试解决给服务器添加目标网站 host,这个问题确切说不是手机浏览器不能发送请求,而是手机本地没有设置代理(电脑开发机通过修改 /etc/hosts 可以发送请求)。
* 手机端浏览器 Uncaught (in promise) Error: Network Error
*: 先确定问题在哪里
*: <syntaxhighlight lang="javascript" highlight='3-5'>axios.get('/disease/footer_recommend').then((req) => {
  _self.Disease_footer_recommend = req.data.data;
}).catch((error)=>{
  console.log(error);
  _self.errorMessage = error;
});</syntaxhighlight>
*: <pre>
Error: Network Error
    at e.exports (spread.js:25)
    at XMLHttpRequest.l.onerror (spread.js:25)</pre>
:* 这个问题源于 我设置的 <code>axios.defaults.baseURL='http://localhost:3000';</code>,网络请求地址指向了开发机自己,当用其他机器测试时请求地址指向测试机地址,所以抛错。
:* 解决办法分三步
:* {{hc|package.json|<syntaxhighlight lang="javascript">
"sshbuild": "export NODE_ENV=production HOST=152.32.132.166 && webpack --mode production --config webpack.config.js",
</syntaxhighlight>}}
:* {{hc|webpack.config.js|<syntaxhighlight lang="javascript">
const AXIOSHOST = process.env.HOST;
/**
* 配置全局常量
*/
new webpack.DefinePlugin({
  'axios_host':JSON.stringify(AXIOSHOST),
}),
</syntaxhighlight>}}
:* {{hc|router/index.js|<syntaxhighlight lang="javascript">
axios.defaults.baseURL='http://'+axios_host+':3000';
</syntaxhighlight>}}