uniapp问题总结
引入u-view
1. 安装:
选择HBuilderX -----> 工具 -----> 插件市场 ----->
搜索u-view UI, 选择用HBuilderX安装。
安装完之后将uni-modules里的u-view拖出来,放入项目根目录。
虽然引入ui有很多种方式,但还是推荐这种引入方式。
2. 配置
import App from './App'
import uView from "uview-ui";
Vue.use(uView);
@import 'uview-ui/theme.scss';
<style lang="scss">
@import "uview-ui/index.scss";
</style>
{
"easycom": {
"^u-(.*)": "@/uview-ui/components/u-$1/u-$1.vue"
},
"pages": [
]
}
参考资料:
https://blog.csdn.net/weixin_46231579/article/details/120913279
https://www.csdn.net/tags/MtTaEg0sMTEzODQyLWJsb2cO0O0O.html
引入多个组件 与 动态组件 配合使用
<view class="category-content">
<view class="category-left">
<view v-for="(item,index) in tabPane" :key='item.key'
class='tab-panes' @click='changeTabpane(item, index)'
:class="{'chooseIndex': item.key === chooseIndex}">
{{item.text}}
</view>
</view>
<view class="category-right">
<component :is='changePriview' class="changeComponent">
</component>
</view>
</view>
export default {
<script lang="js">
import {
TAB_PANE
} from './constants.js';
import RenderContent from './renderContent/renderContent.vue'
const path = require('path');
const files = require.context('./categoryCommon', false, /.vue$/);
const modules = {};
files.keys().forEach(key => {
const name = path.basename(key, '.vue');
modules[name] = files(key).default || files(key);
});
export default {
components: {
...modules,
},
data() {
return {
tabPane: TAB_PANE,
chooseIndex: 'HomePriview',
changeCom: modules
}
},
methods: {
changeTabpane(val, index) {
this.chooseIndex = val.key;
}
},
computed: {
changePriview() {
return this.changeCom[this.chooseIndex];
}
}
}
</script>
<script>
export default {
props: {
changeCom: {
type: Object,
default: () => {}
},
chooseIndex: {
type: String,
default: () => 'HomePriview'
}
},
data() {
return {
name: '天启帝君'
}
},
methods: {
autoChange() {
this.name = '瀚宇星皇'
}
},
computed: {
getNums() {
return 1 + 1;
}
},
render() {
this.autoChange();
console.log('this.name', this.name,'this.getNums', this.getNums);
let Renderview = this.changeCom[this.chooseIndex];
return <view >
<Renderview / >
</view>
}
render(createElement) {
this.autoChange();
console.log('this.name', this.name, 'this.getNums', this.getNums);
let renderview = this.changeCom[this.chooseIndex];
return createElement(renderview)
},
}
</script>
<style>
</style>
<template>
<view class="category">
<view class="top-title">
<view class="title-left">
总览
</view>
<view class="title-right">
列表
</view>
</view>
<view class="category-content">
<view class="category-left">
<view v-for="(item,index) in tabPane" :key='item.key'
class='tab-panes' @click='changeTabpane(item, index)'
:class="{'chooseIndex': item.key === chooseIndex}">
{{item.text}}
</view>
</view>
<view class="category-right">
<RenderContent :changeCom='changeCom' :chooseIndex='chooseIndex' />
</view>
</view>
</view>
</template>
<script lang="js">
import {
TAB_PANE
} from './constants.js';
import RenderContent from './renderContent/renderContent.vue'
const path = require('path');
const files = require.context('./categoryCommon', false, /.vue$/);
const modules = {};
files.keys().forEach(key => {
const name = path.basename(key, '.vue');
modules[name] = files(key).default || files(key);
});
console.log('modules', modules)
export default {
components: {
...modules,
RenderContent
},
data() {
return {
tabPane: TAB_PANE,
chooseIndex: 'HomePriview',
changeCom: modules
}
},
methods: {
changeTabpane(val, index) {
this.chooseIndex = val.key;
}
},
}
</script>
export const TAB_PANE = [{
text: '全部',
key: 'HomePriview'
},
...
..
]