我有一个动态的观点:
<div id="myview">
<div :is="currentComponent"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
与关联的Vue实例:
new Vue ({
data: function () {
return {
currentComponent: 'myComponent',
}
},
}).$mount('#myview');
Run Code Online (Sandbox Code Playgroud)
这允许我动态地更改我的组件.
就我而言,我有三个不同的部分组成:myComponent,myComponent1,和myComponent2.我在他们之间切换如下:
Vue.component('myComponent', {
template: "<button @click=\"$parent.currentComponent = 'myComponent1'\"></button>"
}
Run Code Online (Sandbox Code Playgroud)
现在,我想把道具传递给myComponent1.
当我将组件类型更改为时,如何传递这些道具myComponent1?
我看到该范围返回键和值的"副本".该范围是否有办法返回该项目的地址?例
package main
import "fmt"
type MyType struct {
field string
}
func main() {
var array [10]MyType
for _, e := range array {
e.field = "foo"
}
for _, e := range array {
fmt.Println(e.field)
fmt.Println("--")
}
}
Run Code Online (Sandbox Code Playgroud)
http://play.golang.org/p/AFOGG9NGpx
这里"字段"没有被修改,因为范围发送字段的副本,我是否必须使用索引或是否有任何其他方法来修改值?
谢谢阅读.
我正在尝试使用go将图像从我的计算机上传到网站.通常,我使用bash脚本将文件和密钥发送到服务器:
curl -F "image"=@"IMAGEFILE" -F "key"="KEY" URL
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我正在尝试将此请求转换为我的golang程序.
http://matt.aimonetti.net/posts/2013/07/01/golang-multipart-file-upload-example/
我尝试了这个链接和许多其他链接,但是,对于我尝试的每个代码,来自服务器的响应是"没有图像发送",我不知道为什么.如果有人知道上面的例子发生了什么.
谢谢
我试图把一个中心<v-btn>变成一个<v-flex>.由于<v-flex>是一个flexbox div,我使用justify-center它转换成
justify-content: center
Run Code Online (Sandbox Code Playgroud)
由于我的方向是水平的,我的按钮应该居中对齐,但事实并非如此.这是重现我的问题的codepen.
https://codepen.io/anon/pen/ZXLzex
我想注册按钮在div(v-flex)内居中.
这是完整的代码:
<v-card>
<v-card-text >
<v-text-field label="Email"></v-text-field>
<v-text-field label="Password"></v-text-field>
</v-card-text>
<v-card-actions>
<v-layout row>
<v-flex justify-center>
<v-btn primary>
Signup
</v-btn>
</v-flex>
</v-layout>
</v-card-actions>
</v-card>
Run Code Online (Sandbox Code Playgroud) 我需要Image在30Hz处在组件上绘制图像.我用这个代码:
public MainWindow()
{
InitializeComponent();
Messenger.Default.Register<Bitmap>(this, (bmp) =>
{
ImageTarget.Dispatcher.BeginInvoke((Action)(() =>
{
var hBitmap = bmp.GetHbitmap();
var drawable = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
DeleteObject(hBitmap);
ImageTarget.Source = drawable;
}));
});
}
Run Code Online (Sandbox Code Playgroud)
问题是,使用此代码,我的CPU使用率约为80%,如果没有转换,则大约为6%.
那么为什么转换位图这么久呢?
是否有更快的方法(使用不安全的代码)?
使用WPF和MVVM我试图将相机图像显示为Image.每个帧相机都有一个回调叫做:
视图模型
public void OnNewFrame(object sender, EventArgs e)
{
Camera camera = sender as MyCamera;
camera.ToBitmap(out _bmpImage);
RaisePropertyChanged("BMPImage");
}
Run Code Online (Sandbox Code Playgroud)
每一帧,我更新变量_bmpImage:
视图模型
private Bitmap _bmpImage;
public Bitmap BMPImage
{
get
{ return _bmpImage; }
private set
{ _bmpImage = value; RaisePropertyChanged("BMPImage"); }
}
Run Code Online (Sandbox Code Playgroud)
为了转换Bitmap为BitmapImage我使用转换器:
变流器
public class ImageToSource : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
Image image = value as Image;
if (image != null)
{
MemoryStream ms …Run Code Online (Sandbox Code Playgroud) 为了在我的数据库中创建对象,我已经创建了许多类似的承诺.
var createUserPromise = new Promise(
function(resolve, reject) {
User.create({
email: 'toto@toto.com'
}, function() {
console.log("User populated"); // callback called when user is created
resolve();
});
}
);
Run Code Online (Sandbox Code Playgroud)
最后,我想按照我想要的顺序打电话给我所有的承诺.(因为某些对象依赖于其他对象,所以我需要保留该顺序)
createUserPromise
.then(createCommentPromise
.then(createGamePromise
.then(createRoomPromise)));
Run Code Online (Sandbox Code Playgroud)
所以我希望看到:
User populated
Comment populated
Game populated
Room populated
Run Code Online (Sandbox Code Playgroud)
不幸的是,这些消息被洗牌,我不明白是什么.
谢谢
从MVVM设计模式来看,viewmodel不应该知道视图.但就我而言,我需要视图和模型,我的意思是:
在我的窗口中,我有一个Image组件.当鼠标移过Image组件并将其保存到我的模型中时,我想获得鼠标位置.
背后的代码是:
void Foo_MouseMove(objet sender, MouseEventArgs e)
{
model.x = e.getPosition(this.imageBox).X;
model.y = e.getPosition(this.imageBox).Y;
}
Run Code Online (Sandbox Code Playgroud)
问题是:我需要this.imageBox和MouseEventArgs,所以两个View元素.
我的问题是:如何使用MVVM方法处理这种情况?
我使用MVVM轻量级框架
我刚刚测试了sqlite并创建了一个表.
$sqlite3 plop.db
sqlite> CREATE TABLE t (d DATE);
sqlite> INSERT INTO t (d) VALUES ('Hello');
sqlite> PRAGMA table_info(t);
0|a|DATE|0||0
sqlite> SELECT * FROM t;
Hello
Run Code Online (Sandbox Code Playgroud)
那么,当我尝试将CHAR(5)插入DATE时,为什么没有错误?
我用球拍创造了一个小蛇游戏,我试图展示边界.
我定义了一些constantes:
(define WIDTH 500)
(define HEIGHT 500)
(define BLK_SIZE 10)
Run Code Online (Sandbox Code Playgroud)
所以,所有块都是50px的正方形.
我创建了一个帧%
(define frame
(new (class frame%
(define/augment (on-close)
(send timer stop)
(printf "ending...\n"))
(super-new))
[label "Snake"]
[width WIDTH]
[height HEIGHT]))
Run Code Online (Sandbox Code Playgroud)
和帆布%
(define game-canvas%
(class canvas%
(define/override (on-char e)
(case (send e get-key-code)
[(left) (unless (eq? last-dir 'right)
(set! dir 'left))]
[(right) (unless (eq? last-dir 'left)
(set! dir 'right))]
[(up) (unless (eq? last-dir 'down)
(set! dir 'up))]
[(down) (unless (eq? last-dir 'up)
(set! dir 'down))]
[else (void)]))
(super-new)))
;... …Run Code Online (Sandbox Code Playgroud)