将 appjson 中的 "style": "v2" 去除,小程序的新版基础组件强行加上了许多样式,难以覆盖,不关闭将造成部分组件样式混乱。
开发者工具创建的项目,miniprogramRoot 默认为 miniprogram,packagejson 在其外部,npm 构建无法正常工作。需要手动在 projectconfigjson 内添加如下配置,使开发者工具可以正确索引到 npm 依赖的位置。
打开微信开发者工具,点击 工具 -> 构建 npm ,并勾选 使用 npm 模块 选项,构建完成后,
到 全局配置 appjson 中注册引入组件,详见 快速上手 。
支持default、primary、info、warning、danger五种类型,默认为default。 格式:
通过plain属性将按钮设置为朴素按钮
设置hairline属性可以开启 05px 边框,基于伪类实现。
通过disabled属性来禁用按钮,此时按钮的bind:click事件不会触发。
通过loading属性来设置加载按钮 loading-type="spinner" loading-text="加载中"
通过icon属性设置按钮图标,支持 Icon 组件里的所有图标,也可以传入图标 URL。
label 输入框左侧文本
type 可设置为任意原生类型, 如 number idcard textarea digit
readonly 是否只读
custom-style 自定义样式
autosize 是否自适应内容高度,只对 textarea 有效,可传入对象,如 { maxHeight: 100, minHeight: 50 },单位为px
show :是否显示
onClose 点击其他位置,关闭d出层
position 可以设置为top、bottom、left、right。
Picker 选择器 需要配合d出层使用
<van-picker columns="{{ columns }}" bind:change="onChange" />
columns 对象数组,配置每一列显示的数据
onChange(e) 有默认参数 e
value-key 选项对象中,文字对应的 key 通常用于对象数组
show-toolbar 是否显示顶部栏
defaultIndex 初始选中项的索引,默认为 0 不是双向绑定 需要自己改变defaultIndex 的值 需要渲染两次
覆盖 textarea 等微信小程序原生组件
1子组件使用 position中的 relative、absolute、fixed
//子组件
父组件
此时可以通过z-index 大小控制子组件和 原生组件textarea覆盖 (前提:要在子组件设置position 使得组件脱离文档流)
import javaapplet;
import javaawt;
import javaawtevent;
public class SmallApplet extends Applet implements ActionListener
{
Label lb1,lb2;
Button btn1,btn2;
TextField tf1;
TextArea ta1;
public void init()
{
lb1=new Label("请在文本框中输入内容!");
lb2=new Label("文本区显示的内容为:");
btn1=new Button("提交");
btn2=new Button("退出");
tf1=new TextField(20);
ta1=new TextArea();
add(lb1);
add(tf1);
add(lb2);
add(ta1);
add(btn1);
add(btn2);
setLayout(new FlowLayout());
setSize(600,400);
setVisible(true);
btn1addActionListener(this);
btn2addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(egetSource()==btn1)
{
ta1setText(tf1getText());
}
if(egetSource()==btn2)
{
Systemexit(0);
}
}
}
这行代码[areaappend(s + d1 + " and " + d2 + " so you");]中area为null。
area你是通过方法buildGUI()来初始化的,在新的thread中你没有调用该方法,你是在main方法中对一个匿名Dice调用的[new Dice()buildGUI()]。
下面是改过的,把main中Dice引用传给thread。
import javaawt;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventWindowAdapter;
import javaawteventWindowEvent;
import javautilRandom;
public class Dice {
int d1 = 0, d2 = 0;
float ratio = 10f;
static int win = 0;
static int lose = 0;
Random r = new Random();
int sum;
Frame frame;
TextArea area;
Button button;
String s = "Now you got :";
public static void main(String[] args) {
Dice dice = new Dice();
dicebuildGUI();
createThread c1 = new createThread(dice);// 就是这句!!!
Thread t = new Thread(c1);
tstart();
}
public void buildGUI() {
frame = new Frame("Dice Game");
area = new TextArea();
// button = new Button("Try");
// buttonaddActionListener(new pressListener());
frameadd(BorderLayoutCENTER, area);
// frameadd(BorderLayoutSOUTH, button);
framesetVisible(true);
framesetSize(300, 300);
framesetLocation(100, 100);
frameaddWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Systemexit(-1);
}
});
}
public void createNums() {
d1 = rnextInt(7);
d2 = rnextInt(7);
areaappend(s + d1 + " and " + d2 + " so you");
judge(d1, d2);
}
public void judge(int d1, int d2) {
sum = d1 + d2;
ratio = (float) lose / win;
if (sum > 7) {
win++;
areaappend(" win! " + win + " " + ratio + '\n');
} else {
lose++;
areaappend(" lose " + lose + " " + ratio + '\n');
}
}
/
public class pressListener implements ActionListener { public void actionPerformed(ActionEvent e) { createNums();
} }
/
}
class createThread implements Runnable {
Dice d = new Dice();
public createThread(Dice d) {
thisd = d;
}
public void run() {
try {
Threadsleep(50);
dcreateNums();
} catch (InterruptedException e) {
eprintStackTrace();
}
}
}
以上就是关于微信小程序使用Vant全部的内容,包括:微信小程序使用Vant、微信小程序 通过脱离文档流和z-index 覆盖 原生组件、编写一个Java Applet小程序---请帮个忙,谢谢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)